Submission #718516

#TimeUsernameProblemLanguageResultExecution timeMemory
718516AugustynNaboj (COCI22_naboj)C++17
110 / 110
286 ms15212 KiB
#include<iostream> #include<vector> using namespace std; int n,m; vector<int>*pol; bool *juzodw,*terodw; int *stp_wch,*odp,it; bool dfs(int t) { juzodw[t]=1; terodw[t]=1; for(int i:pol[t]) { if(terodw[i]==1) return 1; if(juzodw[i]==0) if(dfs(i)) return 1; } terodw[t]=0; odp[++it]=t; return 0; } int main() { scanf("%d%d",&n,&m); pol=new vector<int>[n+1]; juzodw=new bool[n+1]; terodw=new bool[n+1]; odp=new int[n+1]; stp_wch=new int[n+1]; while(m) { --m; int a,b; scanf("%d%d",&a,&b); pol[b].push_back(a); stp_wch[a]++; } for(int i=1;i<=n;++i) if(stp_wch[i]==0) if(dfs(i)) { printf("-1"); return 0; } if(it!=n) { 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:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
naboj.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...