#include<stdio.h>
#define N 100000
#define M (2*N)
int ded[N],n, p1[N],head[N], nxt[M], vv[M], eo = 1, tin[N], timer, aux[N],sz[N],qu[N],qh,qt,deg[N];
void link(int u,int v)
{
int i = eo++;
nxt[i]=head[u],vv[i]=v,head[u]=i;
++deg[v];
}
long long max, min;
void dfs(int u,int p)
{
sz[u]=1;
aux[tin[u] = timer++] = u;
for (int j =head[u];j;j=nxt[j])if(p!=vv[j]){
dfs(vv[j],u);
max+=sz[vv[j]]<(n-sz[vv[j]])?sz[vv[j]]:n-sz[vv[j]];
sz[u]+=sz[vv[j]];
}
}
int main()
{
scanf("%d",&n);
for(int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),link(--u,--v),link(v,u);
dfs(0,0);
for(int i=0;i<n;++i)p1[i]=i;
for(int i=0;i<n;++i)if(deg[i]==1)qu[qh++]=i;
while(qh-qt)
{
int temp,u=qu[qt++],f=0;
for(int j=head[u];j;j=nxt[j])
{
int v=vv[j];
if(!ded[v]){
if(--deg[v]==1)
qu[qh++]=v;
f=1;
if(p1[u]==u)
{
min+=2;
temp=p1[u],p1[u]=p1[v],p1[v]=temp;
}
break;
}
}
if(!f&&p1[u]==u)
{
int v=vv[head[u]];
temp=p1[u],p1[u]=p1[v],p1[v]=temp;
min+=2;
}
ded[u]=1;
}
printf("%lld %lld\n",min,max<<1);
for(int i=0;i<n;++i)
printf("%d ",1+p1[i]);
putchar(10);
for(int i=0;i<n;++i)
printf("%d ",1+aux[(tin[i]+n/2)%n]);
}
Compilation message
Village.c: In function 'main':
Village.c:28:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf("%d",&n);
| ^~~~~~~~~~~~~~
Village.c:29:29: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | for(int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),link(--u,--v),link(v,u);
| ^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2472 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2452 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2472 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2452 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2392 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2392 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2392 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
31 ms |
5800 KB |
Output is correct |
49 |
Correct |
34 ms |
6224 KB |
Output is correct |
50 |
Correct |
38 ms |
6228 KB |
Output is correct |
51 |
Correct |
26 ms |
5204 KB |
Output is correct |
52 |
Correct |
36 ms |
6228 KB |
Output is correct |
53 |
Correct |
29 ms |
5712 KB |
Output is correct |
54 |
Correct |
19 ms |
7004 KB |
Output is correct |
55 |
Correct |
38 ms |
12116 KB |
Output is correct |
56 |
Correct |
40 ms |
9044 KB |
Output is correct |
57 |
Correct |
35 ms |
8140 KB |
Output is correct |
58 |
Correct |
35 ms |
7288 KB |
Output is correct |
59 |
Correct |
33 ms |
6236 KB |
Output is correct |
60 |
Correct |
29 ms |
6236 KB |
Output is correct |
61 |
Correct |
28 ms |
6232 KB |
Output is correct |
62 |
Correct |
30 ms |
6228 KB |
Output is correct |
63 |
Correct |
32 ms |
5820 KB |
Output is correct |
64 |
Correct |
31 ms |
6144 KB |
Output is correct |
65 |
Correct |
31 ms |
6476 KB |
Output is correct |
66 |
Correct |
33 ms |
5972 KB |
Output is correct |
67 |
Correct |
21 ms |
4960 KB |
Output is correct |
68 |
Correct |
26 ms |
5456 KB |
Output is correct |
69 |
Correct |
31 ms |
6224 KB |
Output is correct |
70 |
Correct |
29 ms |
6020 KB |
Output is correct |
71 |
Correct |
21 ms |
4948 KB |
Output is correct |
72 |
Correct |
24 ms |
5220 KB |
Output is correct |
73 |
Correct |
32 ms |
6112 KB |
Output is correct |
74 |
Correct |
27 ms |
5976 KB |
Output is correct |
75 |
Correct |
33 ms |
6232 KB |
Output is correct |
76 |
Correct |
32 ms |
6228 KB |
Output is correct |
77 |
Correct |
29 ms |
6028 KB |
Output is correct |
78 |
Correct |
21 ms |
4696 KB |
Output is correct |
79 |
Correct |
26 ms |
5184 KB |
Output is correct |
80 |
Correct |
32 ms |
6224 KB |
Output is correct |
81 |
Correct |
29 ms |
5972 KB |
Output is correct |
82 |
Correct |
31 ms |
6148 KB |
Output is correct |