-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeforces_Mail_Stamps.cpp
More file actions
46 lines (41 loc) · 909 Bytes
/
Copy pathCodeforces_Mail_Stamps.cpp
File metadata and controls
46 lines (41 loc) · 909 Bytes
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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
map<ll,vector<ll>> adjList;
map<ll,ll> notVisited;
void DFS(ll source){
notVisited[source]=0;
cout<<source<<" ";
for(auto neighbour: adjList[source]){
if(notVisited[neighbour])
DFS(neighbour);
}
}
void solve(){
ll n;
ll source;
cin>>n;
for(ll i=0; i<n; i++){
ll x,y;
cin>>x>>y;
adjList[x].push_back(y);
adjList[y].push_back(x);
notVisited[x]++;
notVisited[y]++;
}
for(auto cities: notVisited){
if(cities.second==1)
source=cities.first;
}
DFS(source);
cout<<endl;
}
signed main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
optimize();
solve();
return 0;
}