답안 #661032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
661032 2022-11-24T00:35:17 Z ktkerem Village (BOI20_village) C++17
50 / 100
82 ms 16192 KB
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef std::string str;
/*typedef __int128 vll;
typedef unsigned __int128 uvll;*/
#define llll std::pair<ll , ll>
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e14 + 7; 
const ll ous = 1e5 + 7;
const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1};
ll n , m;std::vector<ll> ar(ous) , mnvr(ous) , mxvr(ous);
ll mna , mxa , ct;
std::vector<ll> adj[ous];
std::vector<ll> v;
bool cmp(ll x , ll y){
    return ar[x] < ar[y];
}
void jd(ll crt , ll prv){
    v.pb(crt);
    for(auto j:adj[crt]){
        if(j != prv){
            jd(j , crt);
        }
    }
}
void klp(ll crt){
    std::sort(all(adj[crt]) , cmp);
    for(auto j:adj[crt]){
        jd(j , crt);
    }
    v.pb(crt);
    for(ll i = 0;v.size()>i;i++){
        mxvr[v[i]] = v[(ll)v.size() - i - 1];
        mxvr[v[(ll)v.size() - i - 1]] = v[i]; 
    }
}
void mdfs(ll crt , ll prv){
    for(auto j:adj[crt]){
        if(j != prv){
            mdfs(j , crt);
        }
    }
    if(crt == mnvr[crt]){
        mna+=2;
        if(prv == -1){
            ll tmp = mnvr[crt];
            mnvr[crt] = mnvr[adj[crt][0]];
            mnvr[adj[crt][0]] = tmp;
        }
        else{
            ll tmp = mnvr[crt];
            mnvr[crt] = mnvr[prv];
            mnvr[prv] = tmp;
        }
    }
}

ll fndcnt(ll crt , ll prv){
    ll z = 1 , mxx = 0;
    for(auto j:adj[crt]){
        if(j != prv){
            ll x = fndcnt(j , crt);
            z+=x;
            mxx += std::max(mxx , x);
        }
    }
    if(n - z <= n/2 && n/2 >= mxx){
        ct = crt;
    }
    return z;
}
ll fndsub(ll crt , ll prv){
    ll z = 1;
    for(auto j:adj[crt]){
        if(j != prv){
            ll x = fndsub(j , crt);
            z+=x;
        }
    }
    if(prv != -1){
        mxa += std::min(z , n - z) * 2;
    }
    ar[crt] = z;
    return z;
}
void solve(){
    std::cin >> n;
    for(ll i = 1;n>i;i++){
        ll x , y;std::cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    for(ll i = 0;n>=i;i++){
        mnvr[i] = i;
        mxvr[i] = i;
    }
    mdfs(1 , -1);
    fndcnt(1 , -1);
    fndsub(ct , -1);
    klp(ct);
    std::cout << mna << " " << mxa << "\n";
    for(ll i = 1;n>=i;i++){
        std::cout << mnvr[i] << " ";
    }
    std::cout << "\n";
    for(ll i = 1;n>=i;i++){
        std::cout << mxvr[i] << " ";   
    }
    std::cout << "\n";
    return;/**/
}
signed main(){
    std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
    ll t=1;
    //std::cin >> t;
    ll o = 1;
    while(t--){ 
        //cout << "Case " << o++ << ":\n";
        solve();
    }
    return 0;
}/**/

Compilation message

Village.cpp:5:78: warning: "/*" within comment [-Wcomment]
    5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
      |                                                                               
Village.cpp: In function 'void klp(ll)':
Village.cpp:45:26: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   45 |     for(ll i = 0;v.size()>i;i++){
      |                  ~~~~~~~~^~
Village.cpp: In function 'int main()':
Village.cpp:129:8: warning: unused variable 'o' [-Wunused-variable]
  129 |     ll o = 1;
      |        ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 3 ms 4948 KB Partially correct
2 Partially correct 2 ms 4948 KB Partially correct
3 Correct 2 ms 4948 KB Output is correct
4 Partially correct 2 ms 4948 KB Partially correct
5 Partially correct 3 ms 4948 KB Partially correct
6 Partially correct 2 ms 4948 KB Partially correct
7 Partially correct 2 ms 4948 KB Partially correct
8 Partially correct 3 ms 4948 KB Partially correct
9 Partially correct 2 ms 4948 KB Partially correct
10 Partially correct 2 ms 4948 KB Partially correct
11 Partially correct 3 ms 4948 KB Partially correct
12 Partially correct 2 ms 4948 KB Partially correct
13 Partially correct 3 ms 4948 KB Partially correct
14 Partially correct 2 ms 4948 KB Partially correct
15 Partially correct 2 ms 5020 KB Partially correct
16 Partially correct 2 ms 4948 KB Partially correct
17 Partially correct 3 ms 4948 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 2 ms 4948 KB Partially correct
2 Partially correct 3 ms 4948 KB Partially correct
3 Partially correct 2 ms 4948 KB Partially correct
4 Partially correct 2 ms 5076 KB Partially correct
5 Partially correct 3 ms 5076 KB Partially correct
6 Partially correct 3 ms 5076 KB Partially correct
7 Partially correct 3 ms 5076 KB Partially correct
8 Partially correct 2 ms 4948 KB Partially correct
9 Partially correct 3 ms 5076 KB Partially correct
10 Correct 3 ms 5076 KB Output is correct
11 Partially correct 2 ms 5076 KB Partially correct
12 Correct 3 ms 5076 KB Output is correct
13 Partially correct 3 ms 5076 KB Partially correct
14 Partially correct 3 ms 4996 KB Partially correct
15 Partially correct 2 ms 5076 KB Partially correct
16 Partially correct 2 ms 5076 KB Partially correct
17 Partially correct 2 ms 5076 KB Partially correct
18 Partially correct 3 ms 5076 KB Partially correct
19 Partially correct 3 ms 5076 KB Partially correct
20 Partially correct 4 ms 5012 KB Partially correct
21 Partially correct 3 ms 5076 KB Partially correct
22 Partially correct 2 ms 4980 KB Partially correct
23 Partially correct 3 ms 5076 KB Partially correct
24 Partially correct 3 ms 4948 KB Partially correct
25 Partially correct 2 ms 4948 KB Partially correct
26 Partially correct 3 ms 5076 KB Partially correct
27 Partially correct 3 ms 4948 KB Partially correct
28 Partially correct 3 ms 5076 KB Partially correct
29 Partially correct 3 ms 5076 KB Partially correct
30 Partially correct 3 ms 5076 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 3 ms 4948 KB Partially correct
2 Partially correct 2 ms 4948 KB Partially correct
3 Correct 2 ms 4948 KB Output is correct
4 Partially correct 2 ms 4948 KB Partially correct
5 Partially correct 3 ms 4948 KB Partially correct
6 Partially correct 2 ms 4948 KB Partially correct
7 Partially correct 2 ms 4948 KB Partially correct
8 Partially correct 3 ms 4948 KB Partially correct
9 Partially correct 2 ms 4948 KB Partially correct
10 Partially correct 2 ms 4948 KB Partially correct
11 Partially correct 3 ms 4948 KB Partially correct
12 Partially correct 2 ms 4948 KB Partially correct
13 Partially correct 3 ms 4948 KB Partially correct
14 Partially correct 2 ms 4948 KB Partially correct
15 Partially correct 2 ms 5020 KB Partially correct
16 Partially correct 2 ms 4948 KB Partially correct
17 Partially correct 3 ms 4948 KB Partially correct
18 Partially correct 2 ms 4948 KB Partially correct
19 Partially correct 3 ms 4948 KB Partially correct
20 Partially correct 2 ms 4948 KB Partially correct
21 Partially correct 2 ms 5076 KB Partially correct
22 Partially correct 3 ms 5076 KB Partially correct
23 Partially correct 3 ms 5076 KB Partially correct
24 Partially correct 3 ms 5076 KB Partially correct
25 Partially correct 2 ms 4948 KB Partially correct
26 Partially correct 3 ms 5076 KB Partially correct
27 Correct 3 ms 5076 KB Output is correct
28 Partially correct 2 ms 5076 KB Partially correct
29 Correct 3 ms 5076 KB Output is correct
30 Partially correct 3 ms 5076 KB Partially correct
31 Partially correct 3 ms 4996 KB Partially correct
32 Partially correct 2 ms 5076 KB Partially correct
33 Partially correct 2 ms 5076 KB Partially correct
34 Partially correct 2 ms 5076 KB Partially correct
35 Partially correct 3 ms 5076 KB Partially correct
36 Partially correct 3 ms 5076 KB Partially correct
37 Partially correct 4 ms 5012 KB Partially correct
38 Partially correct 3 ms 5076 KB Partially correct
39 Partially correct 2 ms 4980 KB Partially correct
40 Partially correct 3 ms 5076 KB Partially correct
41 Partially correct 3 ms 4948 KB Partially correct
42 Partially correct 2 ms 4948 KB Partially correct
43 Partially correct 3 ms 5076 KB Partially correct
44 Partially correct 3 ms 4948 KB Partially correct
45 Partially correct 3 ms 5076 KB Partially correct
46 Partially correct 3 ms 5076 KB Partially correct
47 Partially correct 3 ms 5076 KB Partially correct
48 Partially correct 60 ms 9420 KB Partially correct
49 Partially correct 51 ms 9932 KB Partially correct
50 Partially correct 51 ms 9988 KB Partially correct
51 Partially correct 38 ms 8780 KB Partially correct
52 Partially correct 50 ms 9932 KB Partially correct
53 Partially correct 43 ms 9372 KB Partially correct
54 Partially correct 31 ms 10508 KB Partially correct
55 Partially correct 82 ms 16192 KB Partially correct
56 Correct 80 ms 13588 KB Output is correct
57 Partially correct 57 ms 11732 KB Partially correct
58 Partially correct 77 ms 10896 KB Partially correct
59 Partially correct 52 ms 10008 KB Partially correct
60 Correct 45 ms 10920 KB Output is correct
61 Partially correct 45 ms 10992 KB Partially correct
62 Partially correct 58 ms 11224 KB Partially correct
63 Partially correct 46 ms 10816 KB Partially correct
64 Partially correct 53 ms 11272 KB Partially correct
65 Partially correct 49 ms 11348 KB Partially correct
66 Partially correct 45 ms 10808 KB Partially correct
67 Partially correct 33 ms 9620 KB Partially correct
68 Partially correct 41 ms 10404 KB Partially correct
69 Partially correct 66 ms 11396 KB Partially correct
70 Partially correct 52 ms 10972 KB Partially correct
71 Partially correct 35 ms 9416 KB Partially correct
72 Partially correct 38 ms 9988 KB Partially correct
73 Partially correct 63 ms 11336 KB Partially correct
74 Partially correct 46 ms 10860 KB Partially correct
75 Partially correct 60 ms 10448 KB Partially correct
76 Partially correct 50 ms 9836 KB Partially correct
77 Partially correct 46 ms 10348 KB Partially correct
78 Partially correct 31 ms 8460 KB Partially correct
79 Partially correct 35 ms 8908 KB Partially correct
80 Partially correct 56 ms 10336 KB Partially correct
81 Partially correct 47 ms 10572 KB Partially correct
82 Partially correct 48 ms 10988 KB Partially correct