algorithm_2024/P4017/P4017.cpp

39 lines
943 B
C++
Raw Normal View History

2024-10-03 02:44:17 +00:00
#include <iostream>
2024-10-03 03:09:28 +00:00
#include <ranges>
#include <queue>
2024-10-03 02:44:17 +00:00
using std::cin,std::cout,std::iostream;
2024-10-03 03:09:28 +00:00
static const constexpr auto range {std::ranges::views::iota};
static const constexpr int MOD {80112002}, MAX_TYPES {(int)5e3+5}, MAX_REL_SHIPS {(int)5e5+5};
static int types, rel_ships, a, b, in_degree[MAX_REL_SHIPS], out_degree[MAX_REL_SHIPS];
std::queue<int> q;
std::vector<int> next[MAX_REL_SHIPS];
2024-10-03 02:44:17 +00:00
int main(){
iostream::sync_with_stdio(false);
2024-10-03 03:09:28 +00:00
cin>>types>>rel_ships;
for(const int _:range(1,rel_ships+1)){
cin>>a>>b;
next[a].push_back(b);
in_degree[b]++;
out_degree[a]++;
}
for(const int i:range(1, rel_ships+1)){
if(in_degree[i]==0){
q.push(i);
}
}
while(q.empty()==false){
auto front {q.front()};
q.pop();
for(auto i:next[front]){
if(--in_degree[i]==0){
q.push(i);
}
}
}
2024-10-03 02:44:17 +00:00
}