Submission #718530

#TimeUsernameProblemLanguageResultExecution timeMemory
718530AugustynNaboj (COCI22_naboj)C++17
110 / 110
289 ms17180 KiB
#include<bits/stdc++.h> using namespace std; #define x 200001 int n,m,sw[x],odp[x],it; vector<int>p[x]; bool jo[x],to[x]; bool c; void dfs(int t) { jo[t]=to[t]=1; for(int i:p[t]) { if(to[i]==1) c=1; else if(jo[i]==0) dfs(i); } to[t]=0; odp[++it]=t; } int main() { scanf("%d%d",&n,&m); while(m--) { int a,b; scanf("%d%d",&a,&b); p[b].push_back(a); sw[a]++; } for(int i=1;i<=n;++i) if(sw[i]==0) dfs(i); if(it!=n) c=1; if(c) { printf("-1"); return 0; } printf("%d\n",n); for(int i=1;i<=n;++i) printf("%d 0\n",odp[i]); }

Compilation message (stderr)

naboj.cpp: In function 'int main()':
naboj.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
naboj.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...