update
This commit is contained in:
parent
2556f39372
commit
fc5edbb714
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user