Submission #974402

# Submission time Handle Problem Language Result Execution time Memory
974402 2024-05-03T09:46:24 Z sleepntsheep Village (BOI20_village) C
50 / 100
41 ms 11860 KB
#include<stdio.h>

#define N 100000
#define M (2*N)

int 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(--deg[v]==1){
                qu[qh++]=v;
                min+=2;
                f=1;
                temp=p1[u],p1[u]=p1[v],p1[v]=temp;
                break;
            }
        }
        if(!f)
        {
            int v=vv[head[u]];
            temp=p1[u],p1[u]=p1[v],p1[v]=temp;
            min+=2;
        }
    }

    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 Partially correct 2 ms 2396 KB Partially correct
2 Partially correct 0 ms 2396 KB Partially correct
3 Partially correct 0 ms 2396 KB Partially correct
4 Partially correct 1 ms 2396 KB Partially correct
5 Partially correct 1 ms 2396 KB Partially correct
6 Partially correct 0 ms 2396 KB Partially correct
7 Partially correct 1 ms 2396 KB Partially correct
8 Partially correct 0 ms 2396 KB Partially correct
9 Partially correct 0 ms 2396 KB Partially correct
10 Partially correct 0 ms 2396 KB Partially correct
11 Partially correct 1 ms 2396 KB Partially correct
12 Partially correct 1 ms 2396 KB Partially correct
13 Partially correct 1 ms 2392 KB Partially correct
14 Partially correct 0 ms 2396 KB Partially correct
15 Partially correct 0 ms 2396 KB Partially correct
16 Partially correct 1 ms 2396 KB Partially correct
17 Partially correct 1 ms 2396 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2396 KB Partially correct
2 Partially correct 1 ms 2396 KB Partially correct
3 Partially correct 1 ms 2396 KB Partially correct
4 Partially correct 1 ms 2396 KB Partially correct
5 Partially correct 1 ms 2396 KB Partially correct
6 Partially correct 1 ms 2396 KB Partially correct
7 Partially correct 1 ms 2396 KB Partially correct
8 Partially correct 1 ms 2396 KB Partially correct
9 Partially correct 1 ms 2392 KB Partially correct
10 Partially correct 1 ms 2396 KB Partially correct
11 Partially correct 1 ms 2396 KB Partially correct
12 Partially correct 1 ms 2396 KB Partially correct
13 Partially correct 1 ms 2396 KB Partially correct
14 Partially correct 1 ms 2396 KB Partially correct
15 Partially correct 1 ms 2396 KB Partially correct
16 Partially correct 1 ms 2396 KB Partially correct
17 Partially correct 1 ms 2396 KB Partially correct
18 Partially correct 1 ms 2396 KB Partially correct
19 Partially correct 1 ms 2396 KB Partially correct
20 Partially correct 1 ms 2396 KB Partially correct
21 Partially correct 1 ms 2648 KB Partially correct
22 Partially correct 1 ms 2396 KB Partially correct
23 Partially correct 1 ms 2396 KB Partially correct
24 Partially correct 1 ms 2396 KB Partially correct
25 Partially correct 1 ms 2396 KB Partially correct
26 Partially correct 1 ms 2396 KB Partially correct
27 Partially correct 1 ms 2396 KB Partially correct
28 Partially correct 1 ms 2396 KB Partially correct
29 Partially correct 1 ms 2396 KB Partially correct
30 Partially correct 1 ms 2396 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 2396 KB Partially correct
2 Partially correct 0 ms 2396 KB Partially correct
3 Partially correct 0 ms 2396 KB Partially correct
4 Partially correct 1 ms 2396 KB Partially correct
5 Partially correct 1 ms 2396 KB Partially correct
6 Partially correct 0 ms 2396 KB Partially correct
7 Partially correct 1 ms 2396 KB Partially correct
8 Partially correct 0 ms 2396 KB Partially correct
9 Partially correct 0 ms 2396 KB Partially correct
10 Partially correct 0 ms 2396 KB Partially correct
11 Partially correct 1 ms 2396 KB Partially correct
12 Partially correct 1 ms 2396 KB Partially correct
13 Partially correct 1 ms 2392 KB Partially correct
14 Partially correct 0 ms 2396 KB Partially correct
15 Partially correct 0 ms 2396 KB Partially correct
16 Partially correct 1 ms 2396 KB Partially correct
17 Partially correct 1 ms 2396 KB Partially correct
18 Partially correct 1 ms 2396 KB Partially correct
19 Partially correct 1 ms 2396 KB Partially correct
20 Partially correct 1 ms 2396 KB Partially correct
21 Partially correct 1 ms 2396 KB Partially correct
22 Partially correct 1 ms 2396 KB Partially correct
23 Partially correct 1 ms 2396 KB Partially correct
24 Partially correct 1 ms 2396 KB Partially correct
25 Partially correct 1 ms 2396 KB Partially correct
26 Partially correct 1 ms 2392 KB Partially correct
27 Partially correct 1 ms 2396 KB Partially correct
28 Partially correct 1 ms 2396 KB Partially correct
29 Partially correct 1 ms 2396 KB Partially correct
30 Partially correct 1 ms 2396 KB Partially correct
31 Partially correct 1 ms 2396 KB Partially correct
32 Partially correct 1 ms 2396 KB Partially correct
33 Partially correct 1 ms 2396 KB Partially correct
34 Partially correct 1 ms 2396 KB Partially correct
35 Partially correct 1 ms 2396 KB Partially correct
36 Partially correct 1 ms 2396 KB Partially correct
37 Partially correct 1 ms 2396 KB Partially correct
38 Partially correct 1 ms 2648 KB Partially correct
39 Partially correct 1 ms 2396 KB Partially correct
40 Partially correct 1 ms 2396 KB Partially correct
41 Partially correct 1 ms 2396 KB Partially correct
42 Partially correct 1 ms 2396 KB Partially correct
43 Partially correct 1 ms 2396 KB Partially correct
44 Partially correct 1 ms 2396 KB Partially correct
45 Partially correct 1 ms 2396 KB Partially correct
46 Partially correct 1 ms 2396 KB Partially correct
47 Partially correct 1 ms 2396 KB Partially correct
48 Partially correct 40 ms 5572 KB Partially correct
49 Partially correct 34 ms 5712 KB Partially correct
50 Partially correct 33 ms 5828 KB Partially correct
51 Partially correct 26 ms 4944 KB Partially correct
52 Partially correct 33 ms 5768 KB Partially correct
53 Partially correct 30 ms 5460 KB Partially correct
54 Partially correct 19 ms 6748 KB Partially correct
55 Partially correct 40 ms 11860 KB Partially correct
56 Partially correct 37 ms 8596 KB Partially correct
57 Partially correct 35 ms 7760 KB Partially correct
58 Partially correct 35 ms 6840 KB Partially correct
59 Partially correct 41 ms 5920 KB Partially correct
60 Partially correct 29 ms 5716 KB Partially correct
61 Partially correct 30 ms 5724 KB Partially correct
62 Partially correct 41 ms 5712 KB Partially correct
63 Partially correct 29 ms 5456 KB Partially correct
64 Partially correct 31 ms 5724 KB Partially correct
65 Partially correct 32 ms 5848 KB Partially correct
66 Partially correct 29 ms 5464 KB Partially correct
67 Partially correct 22 ms 4696 KB Partially correct
68 Partially correct 26 ms 5200 KB Partially correct
69 Partially correct 31 ms 5724 KB Partially correct
70 Partially correct 29 ms 5628 KB Partially correct
71 Partially correct 25 ms 4688 KB Partially correct
72 Partially correct 25 ms 4956 KB Partially correct
73 Partially correct 33 ms 5712 KB Partially correct
74 Partially correct 31 ms 5576 KB Partially correct
75 Partially correct 32 ms 5724 KB Partially correct
76 Partially correct 33 ms 5712 KB Partially correct
77 Partially correct 38 ms 5628 KB Partially correct
78 Partially correct 21 ms 4444 KB Partially correct
79 Partially correct 24 ms 4956 KB Partially correct
80 Partially correct 33 ms 5720 KB Partially correct
81 Partially correct 30 ms 5456 KB Partially correct
82 Partially correct 31 ms 5724 KB Partially correct