답안 #986912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986912 2024-05-21T14:39:10 Z aaaaaarroz Village (BOI20_village) C++17
100 / 100
39 ms 13396 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.cpp: In function 'int main()':
Village.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
Village.cpp:29:38: warning: ignoring return value of 'int scanf(const char*, ...)' 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 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 2396 KB Output is correct
5 Correct 1 ms 2392 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 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 1 ms 2396 KB Output is correct
12 Correct 0 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 0 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 2396 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 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 2396 KB Output is correct
13 Correct 1 ms 2468 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 2652 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2392 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 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
# 결과 실행 시간 메모리 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 2396 KB Output is correct
5 Correct 1 ms 2392 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 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 1 ms 2396 KB Output is correct
12 Correct 0 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 0 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 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 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 2396 KB Output is correct
30 Correct 1 ms 2468 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 2652 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2392 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 2396 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 2396 KB Output is correct
48 Correct 30 ms 6896 KB Output is correct
49 Correct 35 ms 7384 KB Output is correct
50 Correct 33 ms 7252 KB Output is correct
51 Correct 26 ms 6152 KB Output is correct
52 Correct 33 ms 7180 KB Output is correct
53 Correct 30 ms 6736 KB Output is correct
54 Correct 19 ms 7408 KB Output is correct
55 Correct 38 ms 13396 KB Output is correct
56 Correct 36 ms 10064 KB Output is correct
57 Correct 36 ms 9300 KB Output is correct
58 Correct 35 ms 8208 KB Output is correct
59 Correct 37 ms 7516 KB Output is correct
60 Correct 30 ms 7252 KB Output is correct
61 Correct 29 ms 7276 KB Output is correct
62 Correct 31 ms 7252 KB Output is correct
63 Correct 29 ms 7004 KB Output is correct
64 Correct 31 ms 7248 KB Output is correct
65 Correct 34 ms 7556 KB Output is correct
66 Correct 28 ms 7004 KB Output is correct
67 Correct 22 ms 5968 KB Output is correct
68 Correct 26 ms 6492 KB Output is correct
69 Correct 31 ms 7260 KB Output is correct
70 Correct 29 ms 6992 KB Output is correct
71 Correct 22 ms 5724 KB Output is correct
72 Correct 25 ms 6228 KB Output is correct
73 Correct 30 ms 7260 KB Output is correct
74 Correct 29 ms 6880 KB Output is correct
75 Correct 33 ms 7200 KB Output is correct
76 Correct 32 ms 7260 KB Output is correct
77 Correct 30 ms 6996 KB Output is correct
78 Correct 21 ms 5460 KB Output is correct
79 Correct 25 ms 6224 KB Output is correct
80 Correct 39 ms 7252 KB Output is correct
81 Correct 37 ms 6996 KB Output is correct
82 Correct 31 ms 7248 KB Output is correct