#line 1 "code.cpp" //#include"testlib.h" #include using namespace std; using lint=long long; #line 4 "cpplib/graph_tree/topological_sort.hpp" /** * @brief トポロジカルソート */ std::vectortsort(std::vector>G){ std::vector in(G.size(),0); std::vector vis(G.size(),0); std::vector res; for(int i=0;i<(int)G.size();i++)for(int j=0;j<(int)G[i].size();j++){ in[G[i][j]]++; } for(int i=0;i<(int)G.size();++i){ auto dfs=[&](auto dfs,int v)->void{ vis[v]=1; res.push_back(v); for(auto e:G[v]){ in[e]--; if(in[e]==0)dfs(dfs,e); } }; if(vis[i]==0&&in[i]==0)dfs(dfs,i); } return res; } #line 6 "code.cpp" const lint N_MIN=1,N_MAX=2000; const lint D_MIN=1,D_MAX=2000; const lint S_MIN=0,S_MAX=2000; // int main(int argc, char** argv){ // //registerValidation(argc, argv); // int n=inf.readInt(N_MIN,N_MAX); // inf.readEoln(); // vector> g(2000); // int s=0; // vector>v(n); // for(int i=0;i>n; vector> g(2000); for(int i=0;i>d; vector v(d); for(int j=0;j>v[j]; if(v[0]!=v.back())g[v[0]].push_back(v.back()); } auto d=tsort(g); if(d.size()!=2000){ cout<<0<