Submission #98419

#TimeUsernameProblemLanguageResultExecution timeMemory
98419KastandaSenior Postmen (BOI14_postmen)C++11
55 / 100
701 ms58512 KiB
#include<bits/stdc++.h> using namespace std; const int N = 500005; int n, m, cyc, from[N], to[N], M[N], S[N], ri[N]; vector < int > Adj[N]; void DFS(int v) { S[v] = 1; #define id (Adj[v][ri[v]]) #define u (from[id] ^ to[id] ^ v) while (ri[v]) { ri[v] --; //int id = Adj[v][ri[v]]; 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"); } #undef id #undef u 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); } mt19937 Rnd(time(0) * 2394); for (int i = 1; i <= n; i++) { ri[i] = Adj[i].size(); shuffle(Adj[i].begin(), Adj[i].end(), Rnd); } vector < int > P(n, 0); iota(P.begin(), P.end(), 1); shuffle(P.begin(), P.end(), Rnd); //for (int i = 1; i <= n; i++) for (int i : P) DFS(i); return 0; }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:41: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:44: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...