Submission #941026

#TimeUsernameProblemLanguageResultExecution timeMemory
941026KaleemRazaSyedSenior Postmen (BOI14_postmen)C++17
0 / 100
6 ms12636 KiB
#include<iostream> #include<vector> using namespace std; const int N = 5e5+5; struct edge { int u, v; bool vis; int other(int x) { return u + v - x; } }; vector<int> G[N]; vector<edge> e; vector<int> p; void dfs(int v) { p.push_back(v); while(G[v].size()) { int i = G[v].back(); G[v].pop_back(); if(e[i].vis) continue; e[i].vis = true; dfs(e[i].other(v)); } } bool seen[N]; int main() { int n, m; cin >> n >> m; for(int i = 0; i < m; i ++) { int u, v; cin >> u >> v; G[u].push_back(i); G[v].push_back(i); e.push_back(edge{u, v, false}); } for(int i = 1; i <= n; i ++) { if(G[i].size()) dfs(i); } vector<int> ans; for(int i = 0; i < p.size(); i++) { if(!seen[p[i]]) ans.push_back(p[i]); else { cout << p[i]; while(ans.back() != p[i]) { cout << ' ' << ans.back(); seen[ans.back()] = false; ans.pop_back(); } cout << '\n'; } seen[p[i]] = true; } return 0; }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int i = 0; i < p.size(); i++)
      |                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...