#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3fm6nhZ ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// difficult !!!
signed main(){
_3fm6nhZ;
int n;
cin>>n;
vec(vi) adj(n);
rep(i,n-1){
int u,v;
cin>>u>>v;
u-=1,v-=1;
adj[u].pb(v);
adj[v].pb(u);
}
int ans=0;
vi ert(n);
auto dfs=[&](auto self,int v,int par)->int{
vi rbts;
for(auto u:adj[v]){
if(u==par) continue;
int e=self(self,u,v);
if(e) rbts.pb(u);
}
if(sz(rbts)==0) return 1;
for(int i=0;i<sz(rbts)-sz(rbts)%2;i+=2){
ert[rbts[i]]=rbts[i+1];
ert[rbts[i+1]]=rbts[i];
ans+=4;
}
if(sz(rbts)%2){
ert[v]=rbts.back();
ert[rbts.back()]=v;
ans+=2;
}else{
ert[v]=rbts.back();
ert[ert[rbts.back()]]=v;
}
return 0;
};
int e=dfs(dfs,0,-1);
if(e){
int v=0;
int u=adj[0][0];
ans+=2;
rep(s,n){
if(ert[s]==u){
ert[v]=u;
ert[s]=0;
break;
}
}
}
cout<<ans<<" "<<ans<<"\n";
rep(t,2){
rep(i,n)cout<<ert[i]+1<<" ";
print();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
212 KB |
Partially correct |
2 |
Partially correct |
0 ms |
212 KB |
Partially correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Partially correct |
0 ms |
212 KB |
Partially correct |
5 |
Partially correct |
0 ms |
212 KB |
Partially correct |
6 |
Partially correct |
0 ms |
212 KB |
Partially correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Partially correct |
0 ms |
212 KB |
Partially correct |
9 |
Partially correct |
1 ms |
212 KB |
Partially correct |
10 |
Partially correct |
0 ms |
212 KB |
Partially correct |
11 |
Partially correct |
0 ms |
212 KB |
Partially correct |
12 |
Partially correct |
0 ms |
212 KB |
Partially correct |
13 |
Partially correct |
0 ms |
212 KB |
Partially correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Partially correct |
0 ms |
212 KB |
Partially correct |
16 |
Partially correct |
0 ms |
212 KB |
Partially correct |
17 |
Partially correct |
0 ms |
212 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
212 KB |
Partially correct |
2 |
Partially correct |
0 ms |
340 KB |
Partially correct |
3 |
Partially correct |
1 ms |
340 KB |
Partially correct |
4 |
Partially correct |
1 ms |
340 KB |
Partially correct |
5 |
Partially correct |
1 ms |
340 KB |
Partially correct |
6 |
Partially correct |
1 ms |
340 KB |
Partially correct |
7 |
Partially correct |
1 ms |
468 KB |
Partially correct |
8 |
Partially correct |
1 ms |
340 KB |
Partially correct |
9 |
Partially correct |
2 ms |
340 KB |
Partially correct |
10 |
Partially correct |
1 ms |
340 KB |
Partially correct |
11 |
Partially correct |
1 ms |
412 KB |
Partially correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Partially correct |
1 ms |
340 KB |
Partially correct |
14 |
Partially correct |
1 ms |
340 KB |
Partially correct |
15 |
Partially correct |
1 ms |
340 KB |
Partially correct |
16 |
Partially correct |
1 ms |
340 KB |
Partially correct |
17 |
Partially correct |
1 ms |
340 KB |
Partially correct |
18 |
Partially correct |
1 ms |
340 KB |
Partially correct |
19 |
Partially correct |
1 ms |
340 KB |
Partially correct |
20 |
Partially correct |
1 ms |
340 KB |
Partially correct |
21 |
Partially correct |
1 ms |
340 KB |
Partially correct |
22 |
Partially correct |
1 ms |
340 KB |
Partially correct |
23 |
Partially correct |
1 ms |
340 KB |
Partially correct |
24 |
Partially correct |
1 ms |
340 KB |
Partially correct |
25 |
Partially correct |
1 ms |
340 KB |
Partially correct |
26 |
Partially correct |
1 ms |
340 KB |
Partially correct |
27 |
Partially correct |
1 ms |
340 KB |
Partially correct |
28 |
Partially correct |
1 ms |
340 KB |
Partially correct |
29 |
Partially correct |
1 ms |
340 KB |
Partially correct |
30 |
Partially correct |
1 ms |
340 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
212 KB |
Partially correct |
2 |
Partially correct |
0 ms |
212 KB |
Partially correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Partially correct |
0 ms |
212 KB |
Partially correct |
5 |
Partially correct |
0 ms |
212 KB |
Partially correct |
6 |
Partially correct |
0 ms |
212 KB |
Partially correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Partially correct |
0 ms |
212 KB |
Partially correct |
9 |
Partially correct |
1 ms |
212 KB |
Partially correct |
10 |
Partially correct |
0 ms |
212 KB |
Partially correct |
11 |
Partially correct |
0 ms |
212 KB |
Partially correct |
12 |
Partially correct |
0 ms |
212 KB |
Partially correct |
13 |
Partially correct |
0 ms |
212 KB |
Partially correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Partially correct |
0 ms |
212 KB |
Partially correct |
16 |
Partially correct |
0 ms |
212 KB |
Partially correct |
17 |
Partially correct |
0 ms |
212 KB |
Partially correct |
18 |
Partially correct |
0 ms |
212 KB |
Partially correct |
19 |
Partially correct |
0 ms |
340 KB |
Partially correct |
20 |
Partially correct |
1 ms |
340 KB |
Partially correct |
21 |
Partially correct |
1 ms |
340 KB |
Partially correct |
22 |
Partially correct |
1 ms |
340 KB |
Partially correct |
23 |
Partially correct |
1 ms |
340 KB |
Partially correct |
24 |
Partially correct |
1 ms |
468 KB |
Partially correct |
25 |
Partially correct |
1 ms |
340 KB |
Partially correct |
26 |
Partially correct |
2 ms |
340 KB |
Partially correct |
27 |
Partially correct |
1 ms |
340 KB |
Partially correct |
28 |
Partially correct |
1 ms |
412 KB |
Partially correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Partially correct |
1 ms |
340 KB |
Partially correct |
31 |
Partially correct |
1 ms |
340 KB |
Partially correct |
32 |
Partially correct |
1 ms |
340 KB |
Partially correct |
33 |
Partially correct |
1 ms |
340 KB |
Partially correct |
34 |
Partially correct |
1 ms |
340 KB |
Partially correct |
35 |
Partially correct |
1 ms |
340 KB |
Partially correct |
36 |
Partially correct |
1 ms |
340 KB |
Partially correct |
37 |
Partially correct |
1 ms |
340 KB |
Partially correct |
38 |
Partially correct |
1 ms |
340 KB |
Partially correct |
39 |
Partially correct |
1 ms |
340 KB |
Partially correct |
40 |
Partially correct |
1 ms |
340 KB |
Partially correct |
41 |
Partially correct |
1 ms |
340 KB |
Partially correct |
42 |
Partially correct |
1 ms |
340 KB |
Partially correct |
43 |
Partially correct |
1 ms |
340 KB |
Partially correct |
44 |
Partially correct |
1 ms |
340 KB |
Partially correct |
45 |
Partially correct |
1 ms |
340 KB |
Partially correct |
46 |
Partially correct |
1 ms |
340 KB |
Partially correct |
47 |
Partially correct |
1 ms |
340 KB |
Partially correct |
48 |
Partially correct |
53 ms |
6864 KB |
Partially correct |
49 |
Partially correct |
61 ms |
7420 KB |
Partially correct |
50 |
Partially correct |
51 ms |
7472 KB |
Partially correct |
51 |
Partially correct |
47 ms |
6056 KB |
Partially correct |
52 |
Partially correct |
65 ms |
7336 KB |
Partially correct |
53 |
Partially correct |
46 ms |
6696 KB |
Partially correct |
54 |
Partially correct |
35 ms |
10752 KB |
Partially correct |
55 |
Partially correct |
74 ms |
22400 KB |
Partially correct |
56 |
Partially correct |
63 ms |
14772 KB |
Partially correct |
57 |
Partially correct |
56 ms |
12236 KB |
Partially correct |
58 |
Partially correct |
56 ms |
10020 KB |
Partially correct |
59 |
Partially correct |
67 ms |
7628 KB |
Partially correct |
60 |
Correct |
46 ms |
7896 KB |
Output is correct |
61 |
Partially correct |
46 ms |
7952 KB |
Partially correct |
62 |
Partially correct |
50 ms |
7868 KB |
Partially correct |
63 |
Partially correct |
48 ms |
7372 KB |
Partially correct |
64 |
Partially correct |
47 ms |
7772 KB |
Partially correct |
65 |
Partially correct |
47 ms |
8012 KB |
Partially correct |
66 |
Partially correct |
45 ms |
7428 KB |
Partially correct |
67 |
Partially correct |
33 ms |
6012 KB |
Partially correct |
68 |
Partially correct |
40 ms |
6728 KB |
Partially correct |
69 |
Partially correct |
49 ms |
7952 KB |
Partially correct |
70 |
Partially correct |
54 ms |
7500 KB |
Partially correct |
71 |
Partially correct |
28 ms |
5588 KB |
Partially correct |
72 |
Partially correct |
34 ms |
6264 KB |
Partially correct |
73 |
Partially correct |
47 ms |
7944 KB |
Partially correct |
74 |
Partially correct |
38 ms |
7304 KB |
Partially correct |
75 |
Partially correct |
62 ms |
7268 KB |
Partially correct |
76 |
Partially correct |
51 ms |
7356 KB |
Partially correct |
77 |
Partially correct |
45 ms |
7452 KB |
Partially correct |
78 |
Partially correct |
35 ms |
5332 KB |
Partially correct |
79 |
Partially correct |
36 ms |
5964 KB |
Partially correct |
80 |
Partially correct |
51 ms |
7244 KB |
Partially correct |
81 |
Partially correct |
55 ms |
7612 KB |
Partially correct |
82 |
Partially correct |
42 ms |
7628 KB |
Partially correct |