#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int>ans;
vector<vector<int>>graph;
int respuesta=0;
void dfs(int nodo, int p){
for(int u:graph[nodo]){
if(u!=p){
dfs(u,nodo);
}
}
if(ans[nodo]==nodo){
respuesta+=2;
if(p){
swap(ans[nodo],ans[p]);
}
else{
swap(ans[nodo],ans[graph[nodo][0]]);
}
}
}
int main() {
ll n;
cin>>n;
graph.resize(n+1,vector<int>());
for(int i=0;i<n-1;i++){
int a, b;
cin>>a>>b;
graph[a].push_back(b);
graph[b].push_back(a);
}
ans.resize(n+1);
for(int i=1;i<=n;i++){
ans[i]=i;
}
dfs(1,0);
cout<<respuesta<<" "<<respuesta<<"\n";
for(int i=1;i<=n;i++){
cout<<ans[i]<<" ";
}
cout<<"\n";
for(int i=1;i<=n;i++){
cout<<ans[i]<<" ";
}
cout<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
348 KB |
Partially correct |
2 |
Partially correct |
0 ms |
344 KB |
Partially correct |
3 |
Correct |
0 ms |
432 KB |
Output is correct |
4 |
Partially correct |
0 ms |
348 KB |
Partially correct |
5 |
Partially correct |
0 ms |
348 KB |
Partially correct |
6 |
Partially correct |
0 ms |
348 KB |
Partially correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Partially correct |
0 ms |
348 KB |
Partially correct |
9 |
Partially correct |
1 ms |
420 KB |
Partially correct |
10 |
Partially correct |
0 ms |
348 KB |
Partially correct |
11 |
Partially correct |
1 ms |
432 KB |
Partially correct |
12 |
Partially correct |
1 ms |
428 KB |
Partially correct |
13 |
Partially correct |
0 ms |
348 KB |
Partially correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Partially correct |
0 ms |
348 KB |
Partially correct |
16 |
Partially correct |
0 ms |
348 KB |
Partially correct |
17 |
Partially correct |
0 ms |
348 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
348 KB |
Partially correct |
2 |
Partially correct |
1 ms |
348 KB |
Partially correct |
3 |
Partially correct |
1 ms |
348 KB |
Partially correct |
4 |
Partially correct |
1 ms |
348 KB |
Partially correct |
5 |
Partially correct |
1 ms |
544 KB |
Partially correct |
6 |
Partially correct |
1 ms |
348 KB |
Partially correct |
7 |
Partially correct |
1 ms |
348 KB |
Partially correct |
8 |
Partially correct |
1 ms |
440 KB |
Partially correct |
9 |
Partially correct |
1 ms |
348 KB |
Partially correct |
10 |
Partially correct |
1 ms |
348 KB |
Partially correct |
11 |
Partially correct |
1 ms |
348 KB |
Partially correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Partially correct |
1 ms |
440 KB |
Partially correct |
14 |
Partially correct |
1 ms |
344 KB |
Partially correct |
15 |
Partially correct |
1 ms |
348 KB |
Partially correct |
16 |
Partially correct |
1 ms |
344 KB |
Partially correct |
17 |
Partially correct |
1 ms |
348 KB |
Partially correct |
18 |
Partially correct |
1 ms |
344 KB |
Partially correct |
19 |
Partially correct |
1 ms |
436 KB |
Partially correct |
20 |
Partially correct |
1 ms |
348 KB |
Partially correct |
21 |
Partially correct |
1 ms |
348 KB |
Partially correct |
22 |
Partially correct |
1 ms |
348 KB |
Partially correct |
23 |
Partially correct |
1 ms |
348 KB |
Partially correct |
24 |
Partially correct |
1 ms |
348 KB |
Partially correct |
25 |
Partially correct |
1 ms |
344 KB |
Partially correct |
26 |
Partially correct |
1 ms |
348 KB |
Partially correct |
27 |
Partially correct |
1 ms |
348 KB |
Partially correct |
28 |
Partially correct |
2 ms |
348 KB |
Partially correct |
29 |
Partially correct |
1 ms |
348 KB |
Partially correct |
30 |
Partially correct |
1 ms |
348 KB |
Partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
348 KB |
Partially correct |
2 |
Partially correct |
0 ms |
344 KB |
Partially correct |
3 |
Correct |
0 ms |
432 KB |
Output is correct |
4 |
Partially correct |
0 ms |
348 KB |
Partially correct |
5 |
Partially correct |
0 ms |
348 KB |
Partially correct |
6 |
Partially correct |
0 ms |
348 KB |
Partially correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Partially correct |
0 ms |
348 KB |
Partially correct |
9 |
Partially correct |
1 ms |
420 KB |
Partially correct |
10 |
Partially correct |
0 ms |
348 KB |
Partially correct |
11 |
Partially correct |
1 ms |
432 KB |
Partially correct |
12 |
Partially correct |
1 ms |
428 KB |
Partially correct |
13 |
Partially correct |
0 ms |
348 KB |
Partially correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Partially correct |
0 ms |
348 KB |
Partially correct |
16 |
Partially correct |
0 ms |
348 KB |
Partially correct |
17 |
Partially correct |
0 ms |
348 KB |
Partially correct |
18 |
Partially correct |
1 ms |
348 KB |
Partially correct |
19 |
Partially correct |
1 ms |
348 KB |
Partially correct |
20 |
Partially correct |
1 ms |
348 KB |
Partially correct |
21 |
Partially correct |
1 ms |
348 KB |
Partially correct |
22 |
Partially correct |
1 ms |
544 KB |
Partially correct |
23 |
Partially correct |
1 ms |
348 KB |
Partially correct |
24 |
Partially correct |
1 ms |
348 KB |
Partially correct |
25 |
Partially correct |
1 ms |
440 KB |
Partially correct |
26 |
Partially correct |
1 ms |
348 KB |
Partially correct |
27 |
Partially correct |
1 ms |
348 KB |
Partially correct |
28 |
Partially correct |
1 ms |
348 KB |
Partially correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Partially correct |
1 ms |
440 KB |
Partially correct |
31 |
Partially correct |
1 ms |
344 KB |
Partially correct |
32 |
Partially correct |
1 ms |
348 KB |
Partially correct |
33 |
Partially correct |
1 ms |
344 KB |
Partially correct |
34 |
Partially correct |
1 ms |
348 KB |
Partially correct |
35 |
Partially correct |
1 ms |
344 KB |
Partially correct |
36 |
Partially correct |
1 ms |
436 KB |
Partially correct |
37 |
Partially correct |
1 ms |
348 KB |
Partially correct |
38 |
Partially correct |
1 ms |
348 KB |
Partially correct |
39 |
Partially correct |
1 ms |
348 KB |
Partially correct |
40 |
Partially correct |
1 ms |
348 KB |
Partially correct |
41 |
Partially correct |
1 ms |
348 KB |
Partially correct |
42 |
Partially correct |
1 ms |
344 KB |
Partially correct |
43 |
Partially correct |
1 ms |
348 KB |
Partially correct |
44 |
Partially correct |
1 ms |
348 KB |
Partially correct |
45 |
Partially correct |
2 ms |
348 KB |
Partially correct |
46 |
Partially correct |
1 ms |
348 KB |
Partially correct |
47 |
Partially correct |
1 ms |
348 KB |
Partially correct |
48 |
Partially correct |
63 ms |
7764 KB |
Partially correct |
49 |
Partially correct |
69 ms |
8528 KB |
Partially correct |
50 |
Partially correct |
72 ms |
8688 KB |
Partially correct |
51 |
Partially correct |
55 ms |
6768 KB |
Partially correct |
52 |
Partially correct |
69 ms |
8528 KB |
Partially correct |
53 |
Partially correct |
72 ms |
8020 KB |
Partially correct |
54 |
Partially correct |
37 ms |
7288 KB |
Partially correct |
55 |
Partially correct |
75 ms |
14676 KB |
Partially correct |
56 |
Partially correct |
78 ms |
11404 KB |
Partially correct |
57 |
Partially correct |
72 ms |
10324 KB |
Partially correct |
58 |
Partially correct |
74 ms |
9640 KB |
Partially correct |
59 |
Partially correct |
71 ms |
8788 KB |
Partially correct |
60 |
Correct |
60 ms |
8904 KB |
Output is correct |
61 |
Partially correct |
71 ms |
8948 KB |
Partially correct |
62 |
Partially correct |
65 ms |
9040 KB |
Partially correct |
63 |
Partially correct |
59 ms |
8632 KB |
Partially correct |
64 |
Partially correct |
87 ms |
9044 KB |
Partially correct |
65 |
Partially correct |
86 ms |
9076 KB |
Partially correct |
66 |
Partially correct |
58 ms |
8532 KB |
Partially correct |
67 |
Partially correct |
46 ms |
6736 KB |
Partially correct |
68 |
Partially correct |
70 ms |
7764 KB |
Partially correct |
69 |
Partially correct |
63 ms |
9044 KB |
Partially correct |
70 |
Partially correct |
67 ms |
9044 KB |
Partially correct |
71 |
Partially correct |
43 ms |
6484 KB |
Partially correct |
72 |
Partially correct |
49 ms |
7272 KB |
Partially correct |
73 |
Partially correct |
67 ms |
9068 KB |
Partially correct |
74 |
Partially correct |
73 ms |
8272 KB |
Partially correct |
75 |
Partially correct |
72 ms |
8528 KB |
Partially correct |
76 |
Partially correct |
72 ms |
8532 KB |
Partially correct |
77 |
Partially correct |
66 ms |
8672 KB |
Partially correct |
78 |
Partially correct |
45 ms |
5932 KB |
Partially correct |
79 |
Partially correct |
54 ms |
6880 KB |
Partially correct |
80 |
Partially correct |
74 ms |
8528 KB |
Partially correct |
81 |
Partially correct |
72 ms |
8808 KB |
Partially correct |
82 |
Partially correct |
71 ms |
8788 KB |
Partially correct |