#include<iostream>
#include<vector>
using namespace std;
vector<vector<int> > graph;
vector<int> match,prem;
vector<vector<int> > dp;
void dfs_min(int node,int parent){
for(auto x:graph[node]){
if(x==parent) continue;
dfs_min(x,node);
dp[node][0]+=max(dp[x][0],dp[x][1]);
}
for(auto x:graph[node]){
if(x==parent) continue;
if(dp[node][1]<dp[node][0]-max(dp[x][0],dp[x][1])+dp[x][0]+1){
dp[node][1]=dp[node][0]-max(dp[x][0],dp[x][1])+dp[x][0]+1;
prem[node]=x;
}
}
}
void dfs_match(int node,int parent,bool flag){
if(flag||dp[node][0]>=dp[node][1]){
for(auto x:graph[node]){
if(x==parent) continue;
dfs_match(x,node,0);
}
}
else{
match[node]=prem[node];
match[prem[node]]=node;
for(auto x:graph[node]){
if(x==parent) continue;
if(x==prem[node]) dfs_match(x,node,1);
else dfs_match(x,node,0);
}
}
}
int main(){
int n;
cin>>n;
graph.resize(n+1);
prem.resize(n+1);
int a,b;
for(int i=1;i<n;i++){
cin>>a>>b;
graph[a].push_back(b);
graph[b].push_back(a);
}
dp.resize(n+1,vector<int>(2));
match.resize(n+1,-1);
dfs_min(1,0);
dfs_match(1,0,0);
vector<int> ans_min(n+1);
for(int i=1;i<=n;i++){
if(match[i]!=-1){
ans_min[i]=match[i];
}
else ans_min[i]=i;
}
int min_cnt=max(dp[1][1],dp[1][0])*2;
for(int i=1;i<=n;i++){
if(match[i]==-1){
swap(ans_min[i],ans_min[graph[i][0]]),min_cnt+=2;
}
}
cout<<min_cnt<<" 1\n";
for(int i=1;i<=n;i++) cout<<ans_min[i]<<" \n"[i==n];
for(int i=1;i<=n;i++) cout<<ans_min[i]<<" \n"[i==n];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
Partially correct |
2 |
Partially correct |
0 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 |
0 ms |
436 KB |
Partially correct |
6 |
Partially correct |
0 ms |
344 KB |
Partially correct |
7 |
Partially correct |
0 ms |
436 KB |
Partially correct |
8 |
Partially correct |
1 ms |
348 KB |
Partially correct |
9 |
Partially correct |
0 ms |
348 KB |
Partially correct |
10 |
Partially correct |
0 ms |
348 KB |
Partially correct |
11 |
Partially correct |
0 ms |
348 KB |
Partially correct |
12 |
Partially correct |
0 ms |
348 KB |
Partially correct |
13 |
Partially correct |
1 ms |
348 KB |
Partially correct |
14 |
Partially correct |
0 ms |
436 KB |
Partially correct |
15 |
Partially correct |
0 ms |
600 KB |
Partially correct |
16 |
Partially correct |
0 ms |
348 KB |
Partially correct |
17 |
Partially correct |
0 ms |
348 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
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 |
348 KB |
Partially correct |
6 |
Partially correct |
1 ms |
348 KB |
Partially correct |
7 |
Partially correct |
1 ms |
604 KB |
Partially correct |
8 |
Partially correct |
1 ms |
348 KB |
Partially correct |
9 |
Partially correct |
1 ms |
344 KB |
Partially correct |
10 |
Partially correct |
1 ms |
348 KB |
Partially correct |
11 |
Partially correct |
1 ms |
348 KB |
Partially correct |
12 |
Partially correct |
1 ms |
348 KB |
Partially correct |
13 |
Partially correct |
1 ms |
348 KB |
Partially correct |
14 |
Partially correct |
1 ms |
348 KB |
Partially correct |
15 |
Partially correct |
1 ms |
348 KB |
Partially correct |
16 |
Partially correct |
1 ms |
348 KB |
Partially correct |
17 |
Partially correct |
1 ms |
344 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 |
568 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 |
348 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 |
Partially correct |
1 ms |
348 KB |
Partially correct |
30 |
Partially correct |
1 ms |
348 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
344 KB |
Partially correct |
2 |
Partially correct |
0 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 |
0 ms |
436 KB |
Partially correct |
6 |
Partially correct |
0 ms |
344 KB |
Partially correct |
7 |
Partially correct |
0 ms |
436 KB |
Partially correct |
8 |
Partially correct |
1 ms |
348 KB |
Partially correct |
9 |
Partially correct |
0 ms |
348 KB |
Partially correct |
10 |
Partially correct |
0 ms |
348 KB |
Partially correct |
11 |
Partially correct |
0 ms |
348 KB |
Partially correct |
12 |
Partially correct |
0 ms |
348 KB |
Partially correct |
13 |
Partially correct |
1 ms |
348 KB |
Partially correct |
14 |
Partially correct |
0 ms |
436 KB |
Partially correct |
15 |
Partially correct |
0 ms |
600 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 |
348 KB |
Partially correct |
23 |
Partially correct |
1 ms |
348 KB |
Partially correct |
24 |
Partially correct |
1 ms |
604 KB |
Partially correct |
25 |
Partially correct |
1 ms |
348 KB |
Partially correct |
26 |
Partially correct |
1 ms |
344 KB |
Partially correct |
27 |
Partially correct |
1 ms |
348 KB |
Partially correct |
28 |
Partially correct |
1 ms |
348 KB |
Partially correct |
29 |
Partially correct |
1 ms |
348 KB |
Partially correct |
30 |
Partially correct |
1 ms |
348 KB |
Partially correct |
31 |
Partially correct |
1 ms |
348 KB |
Partially correct |
32 |
Partially correct |
1 ms |
348 KB |
Partially correct |
33 |
Partially correct |
1 ms |
348 KB |
Partially correct |
34 |
Partially correct |
1 ms |
344 KB |
Partially correct |
35 |
Partially correct |
1 ms |
348 KB |
Partially correct |
36 |
Partially correct |
1 ms |
348 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 |
568 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 |
348 KB |
Partially correct |
43 |
Partially correct |
1 ms |
348 KB |
Partially correct |
44 |
Partially correct |
1 ms |
348 KB |
Partially correct |
45 |
Partially correct |
1 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 |
75 ms |
13532 KB |
Partially correct |
49 |
Partially correct |
85 ms |
14932 KB |
Partially correct |
50 |
Partially correct |
83 ms |
14944 KB |
Partially correct |
51 |
Partially correct |
62 ms |
11700 KB |
Partially correct |
52 |
Partially correct |
81 ms |
14604 KB |
Partially correct |
53 |
Partially correct |
73 ms |
13396 KB |
Partially correct |
54 |
Partially correct |
47 ms |
11240 KB |
Partially correct |
55 |
Partially correct |
99 ms |
22368 KB |
Partially correct |
56 |
Partially correct |
93 ms |
18260 KB |
Partially correct |
57 |
Partially correct |
107 ms |
16924 KB |
Partially correct |
58 |
Partially correct |
87 ms |
15956 KB |
Partially correct |
59 |
Partially correct |
86 ms |
14932 KB |
Partially correct |
60 |
Partially correct |
69 ms |
15172 KB |
Partially correct |
61 |
Partially correct |
74 ms |
15308 KB |
Partially correct |
62 |
Partially correct |
77 ms |
15184 KB |
Partially correct |
63 |
Partially correct |
70 ms |
14484 KB |
Partially correct |
64 |
Partially correct |
78 ms |
15324 KB |
Partially correct |
65 |
Partially correct |
75 ms |
15380 KB |
Partially correct |
66 |
Partially correct |
72 ms |
14384 KB |
Partially correct |
67 |
Partially correct |
54 ms |
11336 KB |
Partially correct |
68 |
Partially correct |
65 ms |
12920 KB |
Partially correct |
69 |
Partially correct |
82 ms |
15444 KB |
Partially correct |
70 |
Partially correct |
70 ms |
14416 KB |
Partially correct |
71 |
Partially correct |
51 ms |
10836 KB |
Partially correct |
72 |
Partially correct |
57 ms |
12112 KB |
Partially correct |
73 |
Partially correct |
76 ms |
15440 KB |
Partially correct |
74 |
Partially correct |
69 ms |
14160 KB |
Partially correct |
75 |
Partially correct |
83 ms |
14672 KB |
Partially correct |
76 |
Partially correct |
83 ms |
14672 KB |
Partially correct |
77 |
Partially correct |
75 ms |
14420 KB |
Partially correct |
78 |
Partially correct |
52 ms |
10068 KB |
Partially correct |
79 |
Partially correct |
65 ms |
11788 KB |
Partially correct |
80 |
Partially correct |
101 ms |
14932 KB |
Partially correct |
81 |
Partially correct |
82 ms |
14524 KB |
Partially correct |
82 |
Partially correct |
74 ms |
15188 KB |
Partially correct |