Submission #543948

#TimeUsernameProblemLanguageResultExecution timeMemory
543948OlympiaSenior Postmen (BOI14_postmen)C++17
100 / 100
472 ms40652 KiB
#include <vector> #include <algorithm> #include <iostream> #include <set> #include <cmath> #include <map> #include <random> #include <cassert> #include <ctime> #include <stack> #include <cstdlib> #include <queue> #include <cstdio> #include <limits.h> #pragma GCC target ("avx2") #pragma GCC optimization ("O1") #pragma GCC optimization ("unroll-loops") using namespace std; vector<pair<int,int>> adj[(int)5e5]; bool hasVisited[(int)5e5]; bool okay[(int)5e5]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, M; scanf("%d%d", &N, &M); for (int i = 0; i < M; i++) { int u, v; scanf("%d%d", &u, &v); u--, v--; adj[u].emplace_back(v, i), adj[v].emplace_back(u, i); } for (int i = 0; i < M; i++) { okay[i] = true; } int nodes[(int)5e5]; for (int i = 0; i < N; i++) { int index = 0; nodes[index] = i; bool upd; while (index != -1) { int cur = nodes[index]; hasVisited[cur] = true; upd = false; while (!adj[cur].empty()) { pair<int,int> pr = adj[cur].back(); adj[cur].pop_back(); int j = pr.first; if (!okay[pr.second]) { continue; } okay[pr.second] = false; if (hasVisited[j]) { while (nodes[index] != j) { hasVisited[nodes[index]] = false; printf("%d ", nodes[index] + 1); index--; } printf("%d\n", j + 1); } else { nodes[++index] = j; } upd = true; break; } if (!upd) { index--; } } } }

Compilation message (stderr)

postmen.cpp:16: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   16 | #pragma GCC optimization ("O1")
      | 
postmen.cpp:17: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   17 | #pragma GCC optimization ("unroll-loops")
      | 
postmen.cpp: In function 'int main()':
postmen.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d%d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~
postmen.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...