Submission #115960

#TimeUsernameProblemLanguageResultExecution timeMemory
115960Mahdi_JfriSenior Postmen (BOI14_postmen)C++14
55 / 100
581 ms55296 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int maxn = 5e5 + 20; vector<int> adj[maxn] , path; int from[maxn] , to[maxn]; bool visited[maxn]; void dfs(int v) { while(!adj[v].empty()) { int e = adj[v].back() , u = from[e] ^ to[e] ^ v; adj[v].pop_back(); if(visited[e]) continue; visited[e] = 1; dfs(u); } path.pb(v); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n , m; cin >> n >> m; for(int i = 0; i < m; i++) { int a , b; cin >> a >> b; a-- , b--; adj[a].pb(i); adj[b].pb(i); from[i] = a , to[i] = b; } dfs(0); vector<int> tmp; memset(visited , 0 , sizeof visited); for(auto v : path) { if(visited[v]) { while(tmp.back() != v) cout << tmp.back() + 1 << " " , visited[tmp.back()] = 0 , tmp.pop_back(); tmp.pop_back(); cout << v + 1 << endl; } tmp.pb(v); visited[v] = 1; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...