#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
#define coy cout<<"YES\n"
#define con cout<<"NO\n"
#define co1 cout<<"-1\n"
#define sc(x) scanf("%lld",&x)
#define all(x) x.begin(),x.end()
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int SI=2e5+7;
ll INF=8e18+7;
int MOD=1e9+7;
int dx[] = {1 , -1 , 0 , 0};
int dy[] = {0 , 0 , 1 , -1};
int T=1;
ll ss;
ll n,dp[SI],up[SI],ans[SI];
vector < ll> v[SI];
void bt( int x=1,int pa=0)
{
for (auto i:v[x])
{
if (i==pa)
continue;
bt(i,x);
if (up[i]==0)
{
swap(ans[x],ans[i]);
ss+=2;
up[x]=1;
}
}
}
void solver()
{
cin>>n;
ans[n]=n;
for (int i=1;i<n;i++)
{
ans[i]=i;
int a,b;
cin>>a>>b;
v[a].pb(b);
v[b].pb(a);
}
bt();
if(ans[1]==1)
ss+=2,swap(ans[1],ans[v[1].back()]);
cout <<ss<<" 0\n";
for (int i=1;i<=n;i++)
cout <<ans[i]<<" ";
for (int i=1;i<=n;i++)
cout <<ans[i]<<" ";
}
int main()
{
//fast
while (T--)
solver();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
5008 KB |
Partially correct |
2 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
3 |
Partially correct |
4 ms |
4948 KB |
Partially correct |
4 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
5 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
6 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
7 |
Partially correct |
3 ms |
5004 KB |
Partially correct |
8 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
9 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
10 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
11 |
Partially correct |
3 ms |
5008 KB |
Partially correct |
12 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
13 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
14 |
Partially correct |
3 ms |
5004 KB |
Partially correct |
15 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
16 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
17 |
Partially correct |
4 ms |
5008 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
4 ms |
5008 KB |
Partially correct |
2 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
3 |
Partially correct |
3 ms |
5012 KB |
Partially correct |
4 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
5 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
6 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
7 |
Partially correct |
4 ms |
5028 KB |
Partially correct |
8 |
Partially correct |
4 ms |
5016 KB |
Partially correct |
9 |
Partially correct |
3 ms |
5012 KB |
Partially correct |
10 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
11 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
12 |
Partially correct |
5 ms |
5076 KB |
Partially correct |
13 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
14 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
15 |
Partially correct |
4 ms |
5012 KB |
Partially correct |
16 |
Partially correct |
4 ms |
5012 KB |
Partially correct |
17 |
Partially correct |
4 ms |
5016 KB |
Partially correct |
18 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
19 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
20 |
Partially correct |
4 ms |
5012 KB |
Partially correct |
21 |
Partially correct |
4 ms |
5008 KB |
Partially correct |
22 |
Partially correct |
4 ms |
5012 KB |
Partially correct |
23 |
Partially correct |
3 ms |
5016 KB |
Partially correct |
24 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
25 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
26 |
Partially correct |
4 ms |
5088 KB |
Partially correct |
27 |
Partially correct |
3 ms |
5004 KB |
Partially correct |
28 |
Partially correct |
4 ms |
5008 KB |
Partially correct |
29 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
30 |
Partially correct |
4 ms |
5008 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
5008 KB |
Partially correct |
2 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
3 |
Partially correct |
4 ms |
4948 KB |
Partially correct |
4 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
5 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
6 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
7 |
Partially correct |
3 ms |
5004 KB |
Partially correct |
8 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
9 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
10 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
11 |
Partially correct |
3 ms |
5008 KB |
Partially correct |
12 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
13 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
14 |
Partially correct |
3 ms |
5004 KB |
Partially correct |
15 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
16 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
17 |
Partially correct |
4 ms |
5008 KB |
Partially correct |
18 |
Partially correct |
4 ms |
5008 KB |
Partially correct |
19 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
20 |
Partially correct |
3 ms |
5012 KB |
Partially correct |
21 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
22 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
23 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
24 |
Partially correct |
4 ms |
5028 KB |
Partially correct |
25 |
Partially correct |
4 ms |
5016 KB |
Partially correct |
26 |
Partially correct |
3 ms |
5012 KB |
Partially correct |
27 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
28 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
29 |
Partially correct |
5 ms |
5076 KB |
Partially correct |
30 |
Partially correct |
3 ms |
5076 KB |
Partially correct |
31 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
32 |
Partially correct |
4 ms |
5012 KB |
Partially correct |
33 |
Partially correct |
4 ms |
5012 KB |
Partially correct |
34 |
Partially correct |
4 ms |
5016 KB |
Partially correct |
35 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
36 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
37 |
Partially correct |
4 ms |
5012 KB |
Partially correct |
38 |
Partially correct |
4 ms |
5008 KB |
Partially correct |
39 |
Partially correct |
4 ms |
5012 KB |
Partially correct |
40 |
Partially correct |
3 ms |
5016 KB |
Partially correct |
41 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
42 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
43 |
Partially correct |
4 ms |
5088 KB |
Partially correct |
44 |
Partially correct |
3 ms |
5004 KB |
Partially correct |
45 |
Partially correct |
4 ms |
5008 KB |
Partially correct |
46 |
Partially correct |
4 ms |
5076 KB |
Partially correct |
47 |
Partially correct |
4 ms |
5008 KB |
Partially correct |
48 |
Partially correct |
85 ms |
11892 KB |
Partially correct |
49 |
Partially correct |
120 ms |
12556 KB |
Partially correct |
50 |
Partially correct |
94 ms |
12668 KB |
Partially correct |
51 |
Partially correct |
84 ms |
10836 KB |
Partially correct |
52 |
Partially correct |
108 ms |
12584 KB |
Partially correct |
53 |
Partially correct |
97 ms |
11808 KB |
Partially correct |
54 |
Partially correct |
68 ms |
11904 KB |
Partially correct |
55 |
Partially correct |
95 ms |
19596 KB |
Partially correct |
56 |
Partially correct |
142 ms |
16060 KB |
Partially correct |
57 |
Partially correct |
107 ms |
14816 KB |
Partially correct |
58 |
Partially correct |
112 ms |
13768 KB |
Partially correct |
59 |
Partially correct |
112 ms |
12800 KB |
Partially correct |
60 |
Partially correct |
87 ms |
11904 KB |
Partially correct |
61 |
Partially correct |
80 ms |
11972 KB |
Partially correct |
62 |
Partially correct |
97 ms |
12492 KB |
Partially correct |
63 |
Partially correct |
96 ms |
12180 KB |
Partially correct |
64 |
Partially correct |
106 ms |
12960 KB |
Partially correct |
65 |
Partially correct |
89 ms |
13068 KB |
Partially correct |
66 |
Partially correct |
78 ms |
12000 KB |
Partially correct |
67 |
Partially correct |
61 ms |
10272 KB |
Partially correct |
68 |
Partially correct |
83 ms |
11888 KB |
Partially correct |
69 |
Partially correct |
101 ms |
12996 KB |
Partially correct |
70 |
Partially correct |
87 ms |
12444 KB |
Partially correct |
71 |
Partially correct |
84 ms |
10536 KB |
Partially correct |
72 |
Partially correct |
63 ms |
11232 KB |
Partially correct |
73 |
Partially correct |
108 ms |
13036 KB |
Partially correct |
74 |
Partially correct |
82 ms |
12232 KB |
Partially correct |
75 |
Partially correct |
92 ms |
13124 KB |
Partially correct |
76 |
Partially correct |
98 ms |
12424 KB |
Partially correct |
77 |
Partially correct |
103 ms |
12892 KB |
Partially correct |
78 |
Partially correct |
57 ms |
10164 KB |
Partially correct |
79 |
Partially correct |
65 ms |
11044 KB |
Partially correct |
80 |
Partially correct |
121 ms |
13108 KB |
Partially correct |
81 |
Partially correct |
90 ms |
13004 KB |
Partially correct |
82 |
Partially correct |
106 ms |
12744 KB |
Partially correct |