diff --git a/P4017/P4017.cpp b/P4017/P4017.cpp index f23dcdb..da16799 100644 --- a/P4017/P4017.cpp +++ b/P4017/P4017.cpp @@ -1,9 +1,39 @@ #include +#include +#include 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 q; +std::vector 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); + } + } + } } \ No newline at end of file