This commit is contained in:
Zengtudor 2024-10-03 11:09:28 +08:00
parent 2556f39372
commit fc5edbb714

View File

@ -1,9 +1,39 @@
#include <iostream> #include <iostream>
#include <ranges>
#include <queue>
using std::cin,std::cout,std::iostream; 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(){ int main(){
iostream::sync_with_stdio(false); 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);
}
}
}
} }