#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int mod = 1e9 + 7;
const int N = 2e5;
int dp[N];
int n;
vector<int> g[N];
int ans;
void dfs(int v, int par){
for(int to : g[v]){
if(to != par) dfs(to, v);
}
int to = par;
if(par != v && dp[v] == -1 && dp[to] == -1){
dp[v] = to, dp[to] = v;
ans+= 2;
}
}
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
for(int i = 0;i < N; i++) dp[i] = -1;
cin >> n;
for(int i = 0;i < n-1; i++){
int a, b; cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1, 1);
for(int i = 1;i <= n; i++){
if(dp[i] == -1){
int to = g[i][0];
dp[i] = i;
swap(dp[to], dp[i]);
ans+= 2;
}
}
cout << ans << ' ' << ans << '\n';
for(int i = 1;i <= n; i++) cout << dp[i] << ' ';
cout << '\n';
for(int i = 1;i <= n; i++) cout << dp[i] << ' ';
return 0;
}
Compilation message
Village.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
27 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
2 |
Partially correct |
1 ms |
5724 KB |
Partially correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Partially correct |
1 ms |
5724 KB |
Partially correct |
5 |
Partially correct |
2 ms |
5740 KB |
Partially correct |
6 |
Partially correct |
2 ms |
5720 KB |
Partially correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Partially correct |
1 ms |
5724 KB |
Partially correct |
9 |
Partially correct |
2 ms |
5720 KB |
Partially correct |
10 |
Partially correct |
1 ms |
5724 KB |
Partially correct |
11 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
12 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
13 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
14 |
Correct |
2 ms |
5720 KB |
Output is correct |
15 |
Partially correct |
2 ms |
5720 KB |
Partially correct |
16 |
Partially correct |
1 ms |
5724 KB |
Partially correct |
17 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
2 |
Partially correct |
2 ms |
5932 KB |
Partially correct |
3 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
4 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
5 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
6 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
7 |
Partially correct |
2 ms |
5976 KB |
Partially correct |
8 |
Partially correct |
2 ms |
5976 KB |
Partially correct |
9 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
10 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
11 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
12 |
Correct |
2 ms |
5940 KB |
Output is correct |
13 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
14 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
15 |
Partially correct |
2 ms |
5752 KB |
Partially correct |
16 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
17 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
18 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
19 |
Partially correct |
2 ms |
6232 KB |
Partially correct |
20 |
Partially correct |
2 ms |
5936 KB |
Partially correct |
21 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
22 |
Partially correct |
2 ms |
5976 KB |
Partially correct |
23 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
24 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
25 |
Partially correct |
2 ms |
5936 KB |
Partially correct |
26 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
27 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
28 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
29 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
30 |
Partially correct |
2 ms |
5976 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
2 |
Partially correct |
1 ms |
5724 KB |
Partially correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Partially correct |
1 ms |
5724 KB |
Partially correct |
5 |
Partially correct |
2 ms |
5740 KB |
Partially correct |
6 |
Partially correct |
2 ms |
5720 KB |
Partially correct |
7 |
Correct |
2 ms |
5724 KB |
Output is correct |
8 |
Partially correct |
1 ms |
5724 KB |
Partially correct |
9 |
Partially correct |
2 ms |
5720 KB |
Partially correct |
10 |
Partially correct |
1 ms |
5724 KB |
Partially correct |
11 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
12 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
13 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
14 |
Correct |
2 ms |
5720 KB |
Output is correct |
15 |
Partially correct |
2 ms |
5720 KB |
Partially correct |
16 |
Partially correct |
1 ms |
5724 KB |
Partially correct |
17 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
18 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
19 |
Partially correct |
2 ms |
5932 KB |
Partially correct |
20 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
21 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
22 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
23 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
24 |
Partially correct |
2 ms |
5976 KB |
Partially correct |
25 |
Partially correct |
2 ms |
5976 KB |
Partially correct |
26 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
27 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
28 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
29 |
Correct |
2 ms |
5940 KB |
Output is correct |
30 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
31 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
32 |
Partially correct |
2 ms |
5752 KB |
Partially correct |
33 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
34 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
35 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
36 |
Partially correct |
2 ms |
6232 KB |
Partially correct |
37 |
Partially correct |
2 ms |
5936 KB |
Partially correct |
38 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
39 |
Partially correct |
2 ms |
5976 KB |
Partially correct |
40 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
41 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
42 |
Partially correct |
2 ms |
5936 KB |
Partially correct |
43 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
44 |
Partially correct |
2 ms |
5724 KB |
Partially correct |
45 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
46 |
Partially correct |
2 ms |
5980 KB |
Partially correct |
47 |
Partially correct |
2 ms |
5976 KB |
Partially correct |
48 |
Partially correct |
43 ms |
10836 KB |
Partially correct |
49 |
Partially correct |
36 ms |
11524 KB |
Partially correct |
50 |
Partially correct |
37 ms |
11516 KB |
Partially correct |
51 |
Partially correct |
27 ms |
10064 KB |
Partially correct |
52 |
Partially correct |
35 ms |
11348 KB |
Partially correct |
53 |
Partially correct |
34 ms |
10836 KB |
Partially correct |
54 |
Partially correct |
19 ms |
10556 KB |
Partially correct |
55 |
Partially correct |
38 ms |
15696 KB |
Partially correct |
56 |
Partially correct |
38 ms |
13392 KB |
Partially correct |
57 |
Partially correct |
41 ms |
12624 KB |
Partially correct |
58 |
Partially correct |
42 ms |
12112 KB |
Partially correct |
59 |
Partially correct |
38 ms |
11404 KB |
Partially correct |
60 |
Correct |
29 ms |
11476 KB |
Output is correct |
61 |
Partially correct |
31 ms |
11652 KB |
Partially correct |
62 |
Partially correct |
34 ms |
11856 KB |
Partially correct |
63 |
Partially correct |
30 ms |
11500 KB |
Partially correct |
64 |
Partially correct |
33 ms |
11808 KB |
Partially correct |
65 |
Partially correct |
44 ms |
11776 KB |
Partially correct |
66 |
Partially correct |
30 ms |
11348 KB |
Partially correct |
67 |
Partially correct |
23 ms |
10072 KB |
Partially correct |
68 |
Partially correct |
29 ms |
10776 KB |
Partially correct |
69 |
Partially correct |
35 ms |
11868 KB |
Partially correct |
70 |
Partially correct |
30 ms |
11348 KB |
Partially correct |
71 |
Partially correct |
22 ms |
10068 KB |
Partially correct |
72 |
Partially correct |
24 ms |
10576 KB |
Partially correct |
73 |
Partially correct |
30 ms |
11860 KB |
Partially correct |
74 |
Partially correct |
29 ms |
11356 KB |
Partially correct |
75 |
Partially correct |
36 ms |
11196 KB |
Partially correct |
76 |
Partially correct |
44 ms |
11192 KB |
Partially correct |
77 |
Partially correct |
32 ms |
11600 KB |
Partially correct |
78 |
Partially correct |
24 ms |
9732 KB |
Partially correct |
79 |
Partially correct |
27 ms |
10300 KB |
Partially correct |
80 |
Partially correct |
35 ms |
11348 KB |
Partially correct |
81 |
Partially correct |
34 ms |
11604 KB |
Partially correct |
82 |
Partially correct |
29 ms |
11604 KB |
Partially correct |