Submission #488448

#TimeUsernameProblemLanguageResultExecution timeMemory
488448ntabc05101Senior Postmen (BOI14_postmen)C++17
100 / 100
389 ms64332 KiB
#include<bits/stdc++.h> using namespace std; #define taskname "" const int mxN = 500005; int n, m; vector< array<int, 2> > adj[mxN]; int nxt[mxN]; bool vis[mxN], used[mxN]; void dfs(int u) { if (vis[u]) { while (vis[u]) { vis[u] = 0; cout << 1 + u << " "; u = nxt[u]; } cout << "\n"; } while (!adj[u].empty()) { auto to = adj[u].back(); adj[u].pop_back(); if (!used[to[1]]) { used[to[1]] = 1; vis[u] = 1; nxt[u] = to[0]; dfs(to[0]); } } } int main() { if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } else { if (fopen(taskname".in", "r")) { freopen(taskname".in", "r", stdin); freopen(taskname".out", "w", stdout); } } cin.tie(0)->sync_with_stdio(0); cin >> n >> m; for (int i = 0, x, y; i < m; i++) { cin >> x >> y; x--; y--; adj[x].push_back({y, i}); adj[y].push_back({x, i}); } dfs(0); return 0; }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:36:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
postmen.cpp:37:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   freopen(taskname".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
postmen.cpp:41:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |    freopen(taskname".in", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
postmen.cpp:42:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |    freopen(taskname".out", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...