# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
227178 | tushar_2658 | Senior Postmen (BOI14_postmen) | C++14 | 586 ms | 94328 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
const int maxn = 500005;
multiset<int> edges[maxn];
vector<int> path;
void dfs(int x){
while(!edges[x].empty()){
int i = *edges[x].begin();
edges[x].erase(edges[x].find(i));
edges[i].erase(edges[i].find(x));
dfs(i);
}
path.push_back(x);
}
int main(int argc, char const *argv[])
{
// freopen("in.txt", "r", stdin);
int n, m;
scanf("%d %d", &n, &m);
for(int i = 0; i < m; ++i){
int x, y;
scanf("%d %d", &x, &y);
edges[x].insert(y);
edges[y].insert(x);
}
dfs(1);
path.pop_back();
vector<vector<int>> ans;
vector<bool> vis(n + 1, 0);
stack<int> st;
vector<int> v;
for(auto i : path){
if(vis[i]){
v.clear();
while(st.top() != i){
v.push_back(st.top());
vis[st.top()] = 0;
st.pop();
}
if(st.top() == i){
vis[st.top()] = 0;
v.push_back(st.top());
st.pop();
}
ans.push_back(v);
}
vis[i] = 1;
st.push(i);
}
v.clear();
while(!st.empty()){
v.push_back(st.top());
st.pop();
}
ans.push_back(v);
for(auto i : ans){
for(auto j : i){
printf("%d ", j);
}
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |