Submission #974407

# Submission time Handle Problem Language Result Execution time Memory
974407 2024-05-03T09:51:38 Z sleepntsheep Village (BOI20_village) C
100 / 100
42 ms 12112 KB
#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);
      |                             ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2392 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 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 2392 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 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2648 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 2396 KB Output is correct
26 Correct 1 ms 2496 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 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2392 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 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 2392 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 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 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 2392 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2648 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2496 KB Output is correct
44 Correct 1 ms 2396 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 2392 KB Output is correct
48 Correct 32 ms 5996 KB Output is correct
49 Correct 33 ms 6228 KB Output is correct
50 Correct 33 ms 6496 KB Output is correct
51 Correct 26 ms 5204 KB Output is correct
52 Correct 33 ms 6232 KB Output is correct
53 Correct 29 ms 5708 KB Output is correct
54 Correct 18 ms 7000 KB Output is correct
55 Correct 40 ms 12112 KB Output is correct
56 Correct 42 ms 9080 KB Output is correct
57 Correct 38 ms 8192 KB Output is correct
58 Correct 37 ms 7272 KB Output is correct
59 Correct 36 ms 6156 KB Output is correct
60 Correct 30 ms 6100 KB Output is correct
61 Correct 29 ms 6236 KB Output is correct
62 Correct 30 ms 6236 KB Output is correct
63 Correct 30 ms 5880 KB Output is correct
64 Correct 32 ms 6236 KB Output is correct
65 Correct 30 ms 6224 KB Output is correct
66 Correct 28 ms 5840 KB Output is correct
67 Correct 21 ms 4956 KB Output is correct
68 Correct 32 ms 5468 KB Output is correct
69 Correct 31 ms 6224 KB Output is correct
70 Correct 28 ms 6004 KB Output is correct
71 Correct 21 ms 4824 KB Output is correct
72 Correct 24 ms 5200 KB Output is correct
73 Correct 30 ms 6164 KB Output is correct
74 Correct 35 ms 5712 KB Output is correct
75 Correct 37 ms 6064 KB Output is correct
76 Correct 32 ms 6236 KB Output is correct
77 Correct 29 ms 5980 KB Output is correct
78 Correct 21 ms 4700 KB Output is correct
79 Correct 25 ms 5208 KB Output is correct
80 Correct 32 ms 6236 KB Output is correct
81 Correct 31 ms 5972 KB Output is correct
82 Correct 30 ms 6196 KB Output is correct