Submission #98424

#TimeUsernameProblemLanguageResultExecution timeMemory
98424KastandaSenior Postmen (BOI14_postmen)C++11
100 / 100
439 ms33164 KiB
#include<bits/stdc++.h> using namespace std; const int N = 500005; int n, m, ets, cyc, to[N + N], M[N], S[N]; int head[N], nxt[N + N]; int cnt = 0; void DFS(int v) { cnt ++; assert(cnt <= m + n); S[v] = 1; #define id (head[v]) #define u (to[id]) for (; ~head[v]; head[v] = nxt[head[v]]) { if (M[id >> 1]) continue; M[id >> 1] = 1; if (S[u]) { cyc = u; S[v] = 0; head[v] = nxt[head[v]]; printf("%d", v); return ; } DFS(u); if (cyc) printf(" %d", v); if (cyc != v) { S[v] = 0; head[v] = nxt[head[v]]; return ; } else cyc = 0, printf("\n"); } #undef id #undef u S[v] = 0; } inline void Add(int v, int u) { to[ets] = u; nxt[ets] = head[v]; head[v] = ets; ets ++; } int main() { scanf("%d%d", &n, &m); memset(head, -1, sizeof(head)); for (int i = 1; i <= m; i++) { int v, u; scanf("%d%d", &v, &u); Add(v, u); Add(u, v); } for (int i = 1; i <= n; i++) DFS(i); return 0; }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:49: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:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &v, &u);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...