-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
43 lines (36 loc) · 861 Bytes
/
main.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
#include <bits/stdc++.h>
using namespace std;
vector< vector<int> > tab(100005, vector<int>());
vector< pair<int, int> > pp(100005, pair<int, int>());
bool vis[100005];
int tin = 1;
int tout = 1;
void dfs(int s){
pp[s].first = tin; tin++;
vis[s] = true;
for(int i = 0; i < tab[s].size(); i++){
if(!vis[tab[s][i]]){
dfs(tab[s][i]);
}
}
pp[s].second = tout; tout++;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int v, e; cin >> v; e = v-1;
int a, b;
for(int i = 0; i < e; i++){
cin >> a >> b; a--, b--;
tab[a].push_back(b);
tab[b].push_back(a);
}
dfs(0);
for(int i = 0; i < v; i++)
cout << pp[i].first << ' ';
cout << "\n";
for(int i = 0; i < v; i++)
cout << pp[i].second << ' ';
cout << "\n";
return 0;
}