# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
31535 | ngkan146 | Senior Postmen (BOI14_postmen) | C++98 | 646 ms | 51808 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[1000005];
vector <edge> G[1000005];
bool visited[1000005];
int n,m;
int euler[1000005], eulersize;
int q[1000005], qsize;
void dfs(){
q[qsize++] = 1;
while(qsize){
int u = q[qsize-1];
bool mjk = 0;
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;
mjk = 1;
visited[id] = 1;
q[qsize++] = v;
break;
}
if(mjk) continue;
euler[eulersize++] = u;
--qsize;
}
}
int st[1000005], stsize;
bool used[1000005];
int main(){
scanf("%d %d",&n,&m);
for(int i=1;i<=m;++i){
int x,y;
scanf("%d %d",&x,&y);
G[x].push_back(edge(y,i));
G[y].push_back(edge(x,i));
}
dfs();
for(int i=0;i<eulersize;++i){
if (used[euler[i]]){
while(st[stsize-1] != euler[i]){
printf("%d ",st[stsize-1]);
used[st[stsize-1]] = 0;
--stsize;
};
printf("%d\n",euler[i]);
}
else{
st[stsize++] = euler[i];
used[euler[i]] = 1;
}
}
}
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... |