Submission #98421

#TimeUsernameProblemLanguageResultExecution timeMemory
98421KastandaSenior Postmen (BOI14_postmen)C++11
55 / 100
638 ms54592 KiB
#include<bits/stdc++.h> using namespace std; const int N = 500005; int n, m, cyc, from[N], to[N], M[N], S[N]; int cnt = 0; vector < int > Adj[N]; void DFS(int v) { cnt ++; assert(cnt <= m + n + m + n); S[v] = 1; while (Adj[v].size()) { int id = Adj[v].back(); Adj[v].pop_back(); if (M[id]) continue; M[id] = 1; int u = from[id] ^ to[id] ^ v; if (S[u]) { cyc = u; S[v] = 0; printf("%d", v); return ; } DFS(u); if (cyc) printf(" %d", v); if (cyc != v) { S[v] = 0; return ; } else cyc = 0, printf("\n"); } S[v] = 0; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { scanf("%d%d", &from[i], &to[i]); Adj[from[i]].push_back(i); Adj[to[i]].push_back(i); } for (int i = 1; i <= n; i++) if (Adj[i].size()) DFS(i); return 0; }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
postmen.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &from[i], &to[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...