답안 #925020

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925020 2024-02-10T13:13:05 Z Andrey 수도 (JOI20_capital_city) C++14
100 / 100
437 ms 43096 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> haha[200001];
vector<int> bruh[200001];
vector<int> col(200001);
vector<int> par(200001,-1);
vector<int> st(200001);
vector<int> wut(0);
vector<bool> yay(200001,1);
vector<bool> no(200001,1);
vector<bool> banana(200001,true);

void dfs(int a, int t, int t2) {
    par[a] = t;
    st[a] = 1;
    wut.push_back(a);
    for(int v: haha[a]) {
        if(v != t && banana[v]) {
            dfs(v,a,t2);
            st[a]+=st[v];
        }
    }
}

int dude(int a, int t) {
   // cout << a << endl;
    int ans = INT_MAX;
    int c = a;
    dfs(a,0,t);
    bool yeah = false;
    while(!yeah) {
        yeah = true;
        for(int v: haha[c]) {
            if(banana[v] && st[v]*2 >= st[a] && st[v] < st[c]) {
                yeah = false;
                c = v;
                break;
            }
        }
    }
  //  cout << a << " " << c << endl;
    wut.clear();
    dfs(c,0,t);
    int br = -1,x = 0;
    vector<int> wow(1,col[c]);
    for(int i = 0; i < wow.size() && x == 0; i++) {
        if(yay[wow[i]]) {
            yay[wow[i]] = false;
            br++;
            for(int v: bruh[wow[i]]) {
                if(par[v] == -1) {
                    x = 1;
                    break;
                }
                while(v != 0 && no[v]) {
                    no[v] = false;
                    wow.push_back(col[v]);
                    v = par[v];
                }
            }
        }
    }
    if(x == 0) {
        ans = min(ans,br);
    }
    for(int i = 0; i < wut.size(); i++) {
        no[wut[i]]= true;
        par[wut[i]] = -1;
    }
    for(int i = 0; i < wow.size(); i++) {
        yay[wow[i]] = true;
    }
    banana[c] = false;
    for(int v: haha[c]) {
        if(banana[v]) {
            ans = min(ans,dude(v,c));
        }
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k,a,b;
    cin >> n >> k;
    for(int i = 0; i < n-1; i++) {
        cin >> a >> b;
        haha[a].push_back(b);
        haha[b].push_back(a);
    }
    for(int i = 1; i <= n; i++) {
        cin >> col[i];
        bruh[col[i]].push_back(i);
    }
    cout << dude(1,-1);
    return 0;
}

Compilation message

capital_city.cpp: In function 'int dude(int, int)':
capital_city.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i = 0; i < wow.size() && x == 0; i++) {
      |                    ~~^~~~~~~~~~~~
capital_city.cpp:67:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i = 0; i < wut.size(); i++) {
      |                    ~~^~~~~~~~~~~~
capital_city.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for(int i = 0; i < wow.size(); i++) {
      |                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12120 KB Output is correct
2 Correct 3 ms 12120 KB Output is correct
3 Correct 3 ms 12120 KB Output is correct
4 Correct 3 ms 12120 KB Output is correct
5 Correct 3 ms 12120 KB Output is correct
6 Correct 3 ms 12124 KB Output is correct
7 Correct 4 ms 12280 KB Output is correct
8 Correct 4 ms 12124 KB Output is correct
9 Correct 3 ms 12296 KB Output is correct
10 Correct 4 ms 12120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12120 KB Output is correct
2 Correct 3 ms 12120 KB Output is correct
3 Correct 3 ms 12120 KB Output is correct
4 Correct 3 ms 12120 KB Output is correct
5 Correct 3 ms 12120 KB Output is correct
6 Correct 3 ms 12124 KB Output is correct
7 Correct 4 ms 12280 KB Output is correct
8 Correct 4 ms 12124 KB Output is correct
9 Correct 3 ms 12296 KB Output is correct
10 Correct 4 ms 12120 KB Output is correct
11 Correct 4 ms 12380 KB Output is correct
12 Correct 5 ms 12380 KB Output is correct
13 Correct 5 ms 12380 KB Output is correct
14 Correct 4 ms 12284 KB Output is correct
15 Correct 4 ms 12464 KB Output is correct
16 Correct 5 ms 12380 KB Output is correct
17 Correct 4 ms 12388 KB Output is correct
18 Correct 6 ms 12380 KB Output is correct
19 Correct 4 ms 12316 KB Output is correct
20 Correct 5 ms 12380 KB Output is correct
21 Correct 4 ms 12340 KB Output is correct
22 Correct 5 ms 12628 KB Output is correct
23 Correct 6 ms 12376 KB Output is correct
24 Correct 5 ms 12304 KB Output is correct
25 Correct 5 ms 12380 KB Output is correct
26 Correct 5 ms 12380 KB Output is correct
27 Correct 5 ms 12380 KB Output is correct
28 Correct 5 ms 12380 KB Output is correct
29 Correct 5 ms 12380 KB Output is correct
30 Correct 6 ms 12380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 295 ms 38912 KB Output is correct
2 Correct 180 ms 43028 KB Output is correct
3 Correct 323 ms 42184 KB Output is correct
4 Correct 165 ms 42948 KB Output is correct
5 Correct 316 ms 39364 KB Output is correct
6 Correct 166 ms 42988 KB Output is correct
7 Correct 307 ms 39724 KB Output is correct
8 Correct 171 ms 42892 KB Output is correct
9 Correct 394 ms 38648 KB Output is correct
10 Correct 367 ms 36040 KB Output is correct
11 Correct 391 ms 38984 KB Output is correct
12 Correct 361 ms 41636 KB Output is correct
13 Correct 378 ms 35804 KB Output is correct
14 Correct 363 ms 41928 KB Output is correct
15 Correct 436 ms 41944 KB Output is correct
16 Correct 369 ms 36556 KB Output is correct
17 Correct 393 ms 37100 KB Output is correct
18 Correct 404 ms 37428 KB Output is correct
19 Correct 437 ms 40524 KB Output is correct
20 Correct 400 ms 42696 KB Output is correct
21 Correct 4 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12120 KB Output is correct
2 Correct 3 ms 12120 KB Output is correct
3 Correct 3 ms 12120 KB Output is correct
4 Correct 3 ms 12120 KB Output is correct
5 Correct 3 ms 12120 KB Output is correct
6 Correct 3 ms 12124 KB Output is correct
7 Correct 4 ms 12280 KB Output is correct
8 Correct 4 ms 12124 KB Output is correct
9 Correct 3 ms 12296 KB Output is correct
10 Correct 4 ms 12120 KB Output is correct
11 Correct 4 ms 12380 KB Output is correct
12 Correct 5 ms 12380 KB Output is correct
13 Correct 5 ms 12380 KB Output is correct
14 Correct 4 ms 12284 KB Output is correct
15 Correct 4 ms 12464 KB Output is correct
16 Correct 5 ms 12380 KB Output is correct
17 Correct 4 ms 12388 KB Output is correct
18 Correct 6 ms 12380 KB Output is correct
19 Correct 4 ms 12316 KB Output is correct
20 Correct 5 ms 12380 KB Output is correct
21 Correct 4 ms 12340 KB Output is correct
22 Correct 5 ms 12628 KB Output is correct
23 Correct 6 ms 12376 KB Output is correct
24 Correct 5 ms 12304 KB Output is correct
25 Correct 5 ms 12380 KB Output is correct
26 Correct 5 ms 12380 KB Output is correct
27 Correct 5 ms 12380 KB Output is correct
28 Correct 5 ms 12380 KB Output is correct
29 Correct 5 ms 12380 KB Output is correct
30 Correct 6 ms 12380 KB Output is correct
31 Correct 295 ms 38912 KB Output is correct
32 Correct 180 ms 43028 KB Output is correct
33 Correct 323 ms 42184 KB Output is correct
34 Correct 165 ms 42948 KB Output is correct
35 Correct 316 ms 39364 KB Output is correct
36 Correct 166 ms 42988 KB Output is correct
37 Correct 307 ms 39724 KB Output is correct
38 Correct 171 ms 42892 KB Output is correct
39 Correct 394 ms 38648 KB Output is correct
40 Correct 367 ms 36040 KB Output is correct
41 Correct 391 ms 38984 KB Output is correct
42 Correct 361 ms 41636 KB Output is correct
43 Correct 378 ms 35804 KB Output is correct
44 Correct 363 ms 41928 KB Output is correct
45 Correct 436 ms 41944 KB Output is correct
46 Correct 369 ms 36556 KB Output is correct
47 Correct 393 ms 37100 KB Output is correct
48 Correct 404 ms 37428 KB Output is correct
49 Correct 437 ms 40524 KB Output is correct
50 Correct 400 ms 42696 KB Output is correct
51 Correct 4 ms 12124 KB Output is correct
52 Correct 268 ms 26248 KB Output is correct
53 Correct 278 ms 25932 KB Output is correct
54 Correct 259 ms 26696 KB Output is correct
55 Correct 288 ms 25976 KB Output is correct
56 Correct 325 ms 26020 KB Output is correct
57 Correct 333 ms 26052 KB Output is correct
58 Correct 216 ms 29584 KB Output is correct
59 Correct 245 ms 30240 KB Output is correct
60 Correct 294 ms 29144 KB Output is correct
61 Correct 373 ms 28872 KB Output is correct
62 Correct 176 ms 42956 KB Output is correct
63 Correct 169 ms 43096 KB Output is correct
64 Correct 178 ms 42932 KB Output is correct
65 Correct 180 ms 42956 KB Output is correct
66 Correct 232 ms 35224 KB Output is correct
67 Correct 234 ms 35124 KB Output is correct
68 Correct 200 ms 35196 KB Output is correct
69 Correct 204 ms 35256 KB Output is correct
70 Correct 236 ms 35124 KB Output is correct
71 Correct 226 ms 35204 KB Output is correct
72 Correct 234 ms 35292 KB Output is correct
73 Correct 224 ms 34440 KB Output is correct
74 Correct 199 ms 35312 KB Output is correct
75 Correct 206 ms 35336 KB Output is correct
76 Correct 291 ms 33736 KB Output is correct
77 Correct 284 ms 31188 KB Output is correct
78 Correct 392 ms 37172 KB Output is correct
79 Correct 393 ms 35060 KB Output is correct
80 Correct 417 ms 42196 KB Output is correct
81 Correct 395 ms 38668 KB Output is correct
82 Correct 395 ms 38940 KB Output is correct
83 Correct 423 ms 35528 KB Output is correct
84 Correct 372 ms 41436 KB Output is correct
85 Correct 367 ms 39880 KB Output is correct
86 Correct 375 ms 35208 KB Output is correct
87 Correct 360 ms 36984 KB Output is correct
88 Correct 324 ms 37960 KB Output is correct
89 Correct 322 ms 33992 KB Output is correct
90 Correct 333 ms 33992 KB Output is correct
91 Correct 326 ms 36244 KB Output is correct
92 Correct 328 ms 35012 KB Output is correct
93 Correct 336 ms 34504 KB Output is correct
94 Correct 319 ms 33756 KB Output is correct
95 Correct 319 ms 35280 KB Output is correct
96 Correct 367 ms 34364 KB Output is correct
97 Correct 312 ms 36104 KB Output is correct