39 lines
943 B
C++
39 lines
943 B
C++
#include <iostream>
|
|
#include <ranges>
|
|
#include <queue>
|
|
|
|
using std::cin,std::cout,std::iostream;
|
|
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];
|
|
|
|
int main(){
|
|
iostream::sync_with_stdio(false);
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
} |