Submission #670458

# Submission time Handle Problem Language Result Execution time Memory
670458 2022-12-09T07:29:43 Z jamezzz Village (BOI20_village) C++17
50 / 100
80 ms 9840 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define sf scanf
#define pf printf
#define pb push_back
#define all(x) x.begin(),x.end()
typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;
 
#define maxn 100005
 
int n,mnans,deg[maxn],mnpos[maxn];
vector<int> AL[maxn];

int main(){
    sf("%d",&n);
    for(int i=1;i<n;++i){
        int a,b;sf("%d%d",&a,&b);
        AL[a].pb(b);
        AL[b].pb(a);
        ++deg[a],++deg[b];
    }
    queue<int> q;
    for(int i=1;i<=n;++i){
        mnpos[i]=i;
        if(deg[i]==1)q.push(i);
    }
    while(!q.empty()){
        int u=q.front();q.pop();
        if(mnpos[u]==u){
            int p=-1;
            for(int v:AL[u]){
                if(deg[v]!=0){
                    p=v;
                    break;
                }
            }
            if(p==-1){
                swap(mnpos[AL[u][0]], mnpos[u]);
            }
            else{
                swap(mnpos[p],mnpos[u]);
            }
            mnans+=2;
        }
        for(int v:AL[u]){
            if(deg[v]!=0){
                --deg[v],--deg[u];
                if(deg[v]<=1)q.push(v);
            }
        }
    }
    pf("%d %d\n",mnans,1);
    for(int i=1;i<=n;++i){
        pf("%d ",mnpos[i]);
    }
    pf("\n");
    for(int i=1;i<=n;++i){
        pf("%d ",mnpos[i]);
    }
    pf("\n");
}

Compilation message

Village.cpp: In function 'int main()':
Village.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     sf("%d",&n);
      |       ^
Village.cpp:21:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         int a,b;sf("%d%d",&a,&b);
      |                   ^
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2644 KB Partially correct
2 Partially correct 2 ms 2644 KB Partially correct
3 Partially correct 2 ms 2656 KB Partially correct
4 Partially correct 2 ms 2656 KB Partially correct
5 Partially correct 1 ms 2644 KB Partially correct
6 Partially correct 2 ms 2656 KB Partially correct
7 Partially correct 2 ms 2644 KB Partially correct
8 Partially correct 1 ms 2644 KB Partially correct
9 Partially correct 1 ms 2652 KB Partially correct
10 Partially correct 1 ms 2644 KB Partially correct
11 Partially correct 2 ms 2644 KB Partially correct
12 Partially correct 2 ms 2644 KB Partially correct
13 Partially correct 2 ms 2644 KB Partially correct
14 Partially correct 2 ms 2652 KB Partially correct
15 Partially correct 2 ms 2644 KB Partially correct
16 Partially correct 2 ms 2652 KB Partially correct
17 Partially correct 2 ms 2772 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 2644 KB Partially correct
2 Partially correct 2 ms 2656 KB Partially correct
3 Partially correct 2 ms 2644 KB Partially correct
4 Partially correct 2 ms 2660 KB Partially correct
5 Partially correct 2 ms 2644 KB Partially correct
6 Partially correct 3 ms 2644 KB Partially correct
7 Partially correct 2 ms 2644 KB Partially correct
8 Partially correct 2 ms 2660 KB Partially correct
9 Partially correct 2 ms 2644 KB Partially correct
10 Partially correct 2 ms 2644 KB Partially correct
11 Partially correct 2 ms 2644 KB Partially correct
12 Partially correct 2 ms 2644 KB Partially correct
13 Partially correct 3 ms 2644 KB Partially correct
14 Partially correct 2 ms 2644 KB Partially correct
15 Partially correct 2 ms 2644 KB Partially correct
16 Partially correct 2 ms 2656 KB Partially correct
17 Partially correct 2 ms 2644 KB Partially correct
18 Partially correct 2 ms 2644 KB Partially correct
19 Partially correct 2 ms 2660 KB Partially correct
20 Partially correct 2 ms 2660 KB Partially correct
21 Partially correct 2 ms 2664 KB Partially correct
22 Partially correct 2 ms 2644 KB Partially correct
23 Partially correct 2 ms 2644 KB Partially correct
24 Partially correct 2 ms 2644 KB Partially correct
25 Partially correct 2 ms 2644 KB Partially correct
26 Partially correct 2 ms 2644 KB Partially correct
27 Partially correct 2 ms 2644 KB Partially correct
28 Partially correct 2 ms 2644 KB Partially correct
29 Partially correct 2 ms 2656 KB Partially correct
30 Partially correct 2 ms 2660 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2644 KB Partially correct
2 Partially correct 2 ms 2644 KB Partially correct
3 Partially correct 2 ms 2656 KB Partially correct
4 Partially correct 2 ms 2656 KB Partially correct
5 Partially correct 1 ms 2644 KB Partially correct
6 Partially correct 2 ms 2656 KB Partially correct
7 Partially correct 2 ms 2644 KB Partially correct
8 Partially correct 1 ms 2644 KB Partially correct
9 Partially correct 1 ms 2652 KB Partially correct
10 Partially correct 1 ms 2644 KB Partially correct
11 Partially correct 2 ms 2644 KB Partially correct
12 Partially correct 2 ms 2644 KB Partially correct
13 Partially correct 2 ms 2644 KB Partially correct
14 Partially correct 2 ms 2652 KB Partially correct
15 Partially correct 2 ms 2644 KB Partially correct
16 Partially correct 2 ms 2652 KB Partially correct
17 Partially correct 2 ms 2772 KB Partially correct
18 Partially correct 2 ms 2644 KB Partially correct
19 Partially correct 2 ms 2656 KB Partially correct
20 Partially correct 2 ms 2644 KB Partially correct
21 Partially correct 2 ms 2660 KB Partially correct
22 Partially correct 2 ms 2644 KB Partially correct
23 Partially correct 3 ms 2644 KB Partially correct
24 Partially correct 2 ms 2644 KB Partially correct
25 Partially correct 2 ms 2660 KB Partially correct
26 Partially correct 2 ms 2644 KB Partially correct
27 Partially correct 2 ms 2644 KB Partially correct
28 Partially correct 2 ms 2644 KB Partially correct
29 Partially correct 2 ms 2644 KB Partially correct
30 Partially correct 3 ms 2644 KB Partially correct
31 Partially correct 2 ms 2644 KB Partially correct
32 Partially correct 2 ms 2644 KB Partially correct
33 Partially correct 2 ms 2656 KB Partially correct
34 Partially correct 2 ms 2644 KB Partially correct
35 Partially correct 2 ms 2644 KB Partially correct
36 Partially correct 2 ms 2660 KB Partially correct
37 Partially correct 2 ms 2660 KB Partially correct
38 Partially correct 2 ms 2664 KB Partially correct
39 Partially correct 2 ms 2644 KB Partially correct
40 Partially correct 2 ms 2644 KB Partially correct
41 Partially correct 2 ms 2644 KB Partially correct
42 Partially correct 2 ms 2644 KB Partially correct
43 Partially correct 2 ms 2644 KB Partially correct
44 Partially correct 2 ms 2644 KB Partially correct
45 Partially correct 2 ms 2644 KB Partially correct
46 Partially correct 2 ms 2656 KB Partially correct
47 Partially correct 2 ms 2660 KB Partially correct
48 Partially correct 57 ms 8536 KB Partially correct
49 Partially correct 60 ms 9164 KB Partially correct
50 Partially correct 68 ms 9244 KB Partially correct
51 Partially correct 44 ms 7696 KB Partially correct
52 Partially correct 59 ms 9112 KB Partially correct
53 Partially correct 56 ms 8476 KB Partially correct
54 Partially correct 30 ms 5676 KB Partially correct
55 Partially correct 64 ms 8776 KB Partially correct
56 Partially correct 63 ms 8880 KB Partially correct
57 Partially correct 69 ms 8908 KB Partially correct
58 Partially correct 78 ms 8936 KB Partially correct
59 Partially correct 62 ms 9144 KB Partially correct
60 Partially correct 53 ms 9548 KB Partially correct
61 Partially correct 57 ms 9704 KB Partially correct
62 Partially correct 57 ms 9780 KB Partially correct
63 Partially correct 52 ms 9332 KB Partially correct
64 Partially correct 62 ms 9636 KB Partially correct
65 Partially correct 59 ms 9728 KB Partially correct
66 Partially correct 49 ms 9296 KB Partially correct
67 Partially correct 38 ms 7884 KB Partially correct
68 Partially correct 46 ms 8636 KB Partially correct
69 Partially correct 53 ms 9840 KB Partially correct
70 Partially correct 48 ms 9352 KB Partially correct
71 Partially correct 37 ms 7560 KB Partially correct
72 Partially correct 42 ms 8300 KB Partially correct
73 Partially correct 57 ms 9804 KB Partially correct
74 Partially correct 58 ms 9232 KB Partially correct
75 Partially correct 80 ms 9036 KB Partially correct
76 Partially correct 67 ms 9136 KB Partially correct
77 Partially correct 57 ms 9420 KB Partially correct
78 Partially correct 38 ms 7072 KB Partially correct
79 Partially correct 45 ms 7876 KB Partially correct
80 Partially correct 70 ms 9016 KB Partially correct
81 Partially correct 72 ms 9548 KB Partially correct
82 Partially correct 61 ms 9640 KB Partially correct