# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
31491 | ngkan146 | Senior Postmen (BOI14_postmen) | C++98 | 530 ms | 53856 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;
struct edge{
int v=0, id=0;
edge(int v=0,int id=0):id(id),v(v){}
};
int ctrl[500005];
vector <edge> G[500005];
bool visited[500005];
int n,m;
vector <int> euler;
void dfs(int u){
for(;ctrl[u]<G[u].size();ctrl[u]++){
int v = G[u][ctrl[u]].v;
int id = G[u][ctrl[u]].id;
if (visited[id]) continue;
visited[id] = 1;
dfs(v);
}
euler.push_back(u);
}
stack <int> st;
bool used[500005];
int main(){
iostream::sync_with_stdio(0);
cin >> n >> m;
for(int i=1;i<=m;i++){
int x,y;
cin >> x >> y;
G[x].push_back(edge(y,i));
G[y].push_back(edge(x,i));
}
for(int i=1;i<=n;i++)
if (ctrl[i] == 0) dfs(i);
for(int i=0;i<euler.size();i++){
if (used[euler[i]]){
int x;
cout << euler[i] << ' ';
do{
used[st.top()] = 0;
cout << st.top() << ' ';
st.pop();
x = st.top();
}while(x != euler[i]);
cout << endl;
}
else{
st.push(euler[i]);
used[euler[i]] = 1;
}
}
// cout << euler[i] << ' ';
}
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... |