-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMail_Delivery.cpp
80 lines (59 loc) · 1.46 KB
/
Mail_Delivery.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include<bits/stdc++.h>
#include <iostream>
#include<vector>
using namespace std;
int v1[2000000];
int v2[2000000];
vector<int>res;
vector<int>adj[2000000];
int vis[2000000];
void dfs(int u)
{
while(adj[u].size())
{
int e=adj[u].back();
adj[u].pop_back();
if(vis[e])
continue;
vis[e]=1;
dfs(v1[e]^v2[e]^u);
res.push_back(u);
}
}
int main()
{
int m,n;
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>v1[i]>>v2[i];
adj[v1[i]].push_back(i);
adj[v2[i]].push_back(i);
}
for(int i=1;i<n+1;i++)
{
if(adj[i].size()&1)
{
cout<<"IMPOSSIBLE";
return 0;
}
}
res.push_back(1);
dfs(1);
if(res.size()^m+1)
{
cout<<"IMPOSSIBLE";
return 0;
}
for(auto nm : res)
{
cout<<nm<<" ";
}
// cout<<endl;
return 0;
}