Submission #543930

#TimeUsernameProblemLanguageResultExecution timeMemory
543930OlympiaSenior Postmen (BOI14_postmen)C++17
38 / 100
79 ms24276 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> using namespace std; vector<pair<int,int>> adj[(int)5e5]; bool hasVisited[(int)5e5]; bool okay[(int)5e5]; int main() { //freopen("balancing.in", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(NULL); int N, M; scanf("%d%d", &N, &M); assert(N != 75000); 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; } stack<pair<int,int>> nodes; for (int i = 0; i < N; i++) { nodes.push({i, -1}); while (!nodes.empty()) { int cur = nodes.top().first; okay[nodes.top().second] = false; hasVisited[cur] = true; bool upd = false; for (pair<int,int> &pr: adj[cur]) { int j = pr.first; if (pr.second == nodes.top().second || !okay[pr.second]) { continue; } okay[pr.second] = false; if (hasVisited[j]) { while (!nodes.empty() && nodes.top().first != j) { hasVisited[nodes.top().first] = false; printf("%d ", nodes.top().first + 1); nodes.pop(); } printf("%d\n", j + 1); } else { nodes.emplace(j, pr.second); } upd = true; break; } if (!upd) { nodes.pop(); } } } }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d%d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~
postmen.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...