답안 #650557

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
650557 2022-10-14T08:23:55 Z DJeniUp Village (BOI20_village) C++17
50 / 100
138 ms 19368 KB
#include "bits/stdc++.h"
//#pragma GCC optimize("O3")
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pairll;
typedef long double ld;
 
#define fr first
#define sc second
#define pb push_back
#define INF 100000000007
#define endl '\n'
#define MOD 998244353
#define A 31
#define N 100007
#define eps 0.000000000001
 
ll n,res[N],resx;

vector<ll>v[N];

pairll S(ll x,ll y){
    vector<pairll>a;
    a.clear();
    pairll b;
    for(int i=0;i<v[x].size();i++){
        if(v[x][i]!=y){
            b=S(v[x][i],x);
            if(b.fr==b.sc)a.pb(b);
        }
    }
    if(a.size()==0){
        if(y==0){
            res[b.sc]=x;
            res[x]=b.fr;
            resx+=2;
            return {0,0};
        }else return {x,x};
    }else{
        a.pb({x,x});
        ll m=a.size()-2;
        for(int i=0;i<=m;i++){
            res[a[i].fr]=a[i+1].fr;
            resx+=2;
        }
        res[x]=a[0].fr;
        return {x,a[m].fr};
    }
}

int main(){
    
    cin>>n;
    for(int i=1;i<n;i++){
        ll x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    S(1,0);
    cout<<resx<<" "<<0<<endl;
    for(int i=1;i<=n;i++){
        cout<<res[i]<<" ";
    }
    cout<<endl;
    for(int i=1;i<=n;i++){
        cout<<i<<" ";
    }
    cout<<endl;
    
    
    return 0;
}

Compilation message

Village.cpp: In function 'pairll S(ll, ll)':
Village.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 2 ms 2644 KB Partially correct
2 Partially correct 2 ms 2644 KB Partially correct
3 Partially correct 2 ms 2660 KB Partially correct
4 Partially correct 2 ms 2656 KB Partially correct
5 Partially correct 2 ms 2656 KB Partially correct
6 Partially correct 2 ms 2644 KB Partially correct
7 Partially correct 2 ms 2660 KB Partially correct
8 Partially correct 2 ms 2656 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 2656 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 2584 KB Partially correct
15 Partially correct 2 ms 2644 KB Partially correct
16 Partially correct 3 ms 2644 KB Partially correct
17 Partially correct 2 ms 2644 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 2 ms 2644 KB Partially correct
2 Partially correct 2 ms 2664 KB Partially correct
3 Partially correct 2 ms 2644 KB Partially correct
4 Partially correct 3 ms 2644 KB Partially correct
5 Partially correct 3 ms 2644 KB Partially correct
6 Partially correct 3 ms 2644 KB Partially correct
7 Partially correct 3 ms 2664 KB Partially correct
8 Partially correct 3 ms 2644 KB Partially correct
9 Partially correct 3 ms 2644 KB Partially correct
10 Partially correct 2 ms 2644 KB Partially correct
11 Partially correct 3 ms 2644 KB Partially correct
12 Partially correct 2 ms 2660 KB Partially correct
13 Partially correct 3 ms 2644 KB Partially correct
14 Partially correct 3 ms 2644 KB Partially correct
15 Partially correct 2 ms 2644 KB Partially correct
16 Partially correct 3 ms 2644 KB Partially correct
17 Partially correct 3 ms 2644 KB Partially correct
18 Partially correct 3 ms 2644 KB Partially correct
19 Partially correct 3 ms 2644 KB Partially correct
20 Partially correct 2 ms 2644 KB Partially correct
21 Partially correct 3 ms 2660 KB Partially correct
22 Partially correct 3 ms 2644 KB Partially correct
23 Partially correct 3 ms 2664 KB Partially correct
24 Partially correct 3 ms 2644 KB Partially correct
25 Partially correct 2 ms 2644 KB Partially correct
26 Partially correct 3 ms 2644 KB Partially correct
27 Partially correct 2 ms 2656 KB Partially correct
28 Partially correct 3 ms 2664 KB Partially correct
29 Partially correct 3 ms 2644 KB Partially correct
30 Partially correct 3 ms 2668 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 2 ms 2644 KB Partially correct
2 Partially correct 2 ms 2644 KB Partially correct
3 Partially correct 2 ms 2660 KB Partially correct
4 Partially correct 2 ms 2656 KB Partially correct
5 Partially correct 2 ms 2656 KB Partially correct
6 Partially correct 2 ms 2644 KB Partially correct
7 Partially correct 2 ms 2660 KB Partially correct
8 Partially correct 2 ms 2656 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 2656 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 2584 KB Partially correct
15 Partially correct 2 ms 2644 KB Partially correct
16 Partially correct 3 ms 2644 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 2664 KB Partially correct
20 Partially correct 2 ms 2644 KB Partially correct
21 Partially correct 3 ms 2644 KB Partially correct
22 Partially correct 3 ms 2644 KB Partially correct
23 Partially correct 3 ms 2644 KB Partially correct
24 Partially correct 3 ms 2664 KB Partially correct
25 Partially correct 3 ms 2644 KB Partially correct
26 Partially correct 3 ms 2644 KB Partially correct
27 Partially correct 2 ms 2644 KB Partially correct
28 Partially correct 3 ms 2644 KB Partially correct
29 Partially correct 2 ms 2660 KB Partially correct
30 Partially correct 3 ms 2644 KB Partially correct
31 Partially correct 3 ms 2644 KB Partially correct
32 Partially correct 2 ms 2644 KB Partially correct
33 Partially correct 3 ms 2644 KB Partially correct
34 Partially correct 3 ms 2644 KB Partially correct
35 Partially correct 3 ms 2644 KB Partially correct
36 Partially correct 3 ms 2644 KB Partially correct
37 Partially correct 2 ms 2644 KB Partially correct
38 Partially correct 3 ms 2660 KB Partially correct
39 Partially correct 3 ms 2644 KB Partially correct
40 Partially correct 3 ms 2664 KB Partially correct
41 Partially correct 3 ms 2644 KB Partially correct
42 Partially correct 2 ms 2644 KB Partially correct
43 Partially correct 3 ms 2644 KB Partially correct
44 Partially correct 2 ms 2656 KB Partially correct
45 Partially correct 3 ms 2664 KB Partially correct
46 Partially correct 3 ms 2644 KB Partially correct
47 Partially correct 3 ms 2668 KB Partially correct
48 Partially correct 99 ms 8884 KB Partially correct
49 Partially correct 100 ms 9464 KB Partially correct
50 Partially correct 124 ms 9448 KB Partially correct
51 Partially correct 78 ms 8076 KB Partially correct
52 Partially correct 138 ms 9440 KB Partially correct
53 Partially correct 86 ms 8712 KB Partially correct
54 Partially correct 64 ms 10628 KB Partially correct
55 Partially correct 124 ms 19368 KB Partially correct
56 Partially correct 120 ms 14668 KB Partially correct
57 Partially correct 118 ms 12736 KB Partially correct
58 Partially correct 127 ms 11196 KB Partially correct
59 Partially correct 117 ms 9724 KB Partially correct
60 Partially correct 94 ms 10088 KB Partially correct
61 Partially correct 90 ms 9752 KB Partially correct
62 Partially correct 88 ms 9892 KB Partially correct
63 Partially correct 85 ms 9432 KB Partially correct
64 Partially correct 100 ms 10012 KB Partially correct
65 Partially correct 95 ms 9988 KB Partially correct
66 Partially correct 79 ms 9484 KB Partially correct
67 Partially correct 68 ms 8540 KB Partially correct
68 Partially correct 85 ms 8808 KB Partially correct
69 Partially correct 108 ms 10196 KB Partially correct
70 Partially correct 97 ms 9560 KB Partially correct
71 Partially correct 78 ms 7712 KB Partially correct
72 Partially correct 79 ms 8464 KB Partially correct
73 Partially correct 116 ms 10140 KB Partially correct
74 Partially correct 95 ms 9348 KB Partially correct
75 Partially correct 126 ms 9956 KB Partially correct
76 Partially correct 123 ms 9372 KB Partially correct
77 Partially correct 122 ms 9804 KB Partially correct
78 Partially correct 65 ms 7500 KB Partially correct
79 Partially correct 90 ms 8100 KB Partially correct
80 Partially correct 106 ms 9880 KB Partially correct
81 Partially correct 110 ms 9956 KB Partially correct
82 Partially correct 87 ms 9668 KB Partially correct