답안 #850764

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850764 2023-09-17T11:51:43 Z oscar1f Power Plant (JOI20_power) C++17
100 / 100
105 ms 27028 KB
#include<bits/stdc++.h>
using namespace std;

const int MAX_SOM=200*1000+5;
int nbSom,debAre,finAre,rep;
vector<int> adja[MAX_SOM];
int val[MAX_SOM],dv[MAX_SOM];
string etatDeb;

int DFS(int pos) {
    if (dv[pos]==0) {
        dv[pos]=1;
        int somme=0,maxi=0,ans;
        for (int i:adja[pos]) {
            ans=DFS(i);
            somme+=ans;
            maxi=max(maxi,ans);
        }
        //cout<<pos<<" "<<maxi<<" "<<somme<<endl;
        rep=max(rep,max(maxi+val[pos],somme-val[pos]));
        return max(somme-val[pos],val[pos]);
    }
    else {
        return 0;
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>nbSom;
    for (int i=0;i<nbSom-1;i++) {
        cin>>debAre>>finAre;
        adja[debAre].push_back(finAre);
        adja[finAre].push_back(debAre);
    }
    cin>>etatDeb;
    for (int i=1;i<=nbSom;i++) {
        if (etatDeb[i-1]=='1') {
            val[i]=1;
        }
    }
    DFS(1);
    cout<<rep<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6520 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 3 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6520 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 3 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6628 KB Output is correct
23 Correct 2 ms 6584 KB Output is correct
24 Correct 3 ms 6492 KB Output is correct
25 Correct 2 ms 6488 KB Output is correct
26 Correct 3 ms 6492 KB Output is correct
27 Correct 2 ms 6560 KB Output is correct
28 Correct 3 ms 6748 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 2 ms 6504 KB Output is correct
32 Correct 3 ms 6492 KB Output is correct
33 Correct 2 ms 6624 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6488 KB Output is correct
40 Correct 3 ms 6492 KB Output is correct
41 Correct 2 ms 6548 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 3 ms 6492 KB Output is correct
44 Correct 2 ms 6640 KB Output is correct
45 Correct 2 ms 6564 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6560 KB Output is correct
48 Correct 3 ms 6492 KB Output is correct
49 Correct 3 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 2 ms 6584 KB Output is correct
52 Correct 2 ms 6488 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 3 ms 6492 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 2 ms 6748 KB Output is correct
58 Correct 2 ms 6492 KB Output is correct
59 Correct 3 ms 6748 KB Output is correct
60 Correct 2 ms 6492 KB Output is correct
61 Correct 2 ms 6560 KB Output is correct
62 Correct 2 ms 6492 KB Output is correct
63 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6520 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 3 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6628 KB Output is correct
23 Correct 2 ms 6584 KB Output is correct
24 Correct 3 ms 6492 KB Output is correct
25 Correct 2 ms 6488 KB Output is correct
26 Correct 3 ms 6492 KB Output is correct
27 Correct 2 ms 6560 KB Output is correct
28 Correct 3 ms 6748 KB Output is correct
29 Correct 2 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 2 ms 6504 KB Output is correct
32 Correct 3 ms 6492 KB Output is correct
33 Correct 2 ms 6624 KB Output is correct
34 Correct 2 ms 6492 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 2 ms 6488 KB Output is correct
40 Correct 3 ms 6492 KB Output is correct
41 Correct 2 ms 6548 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 3 ms 6492 KB Output is correct
44 Correct 2 ms 6640 KB Output is correct
45 Correct 2 ms 6564 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6560 KB Output is correct
48 Correct 3 ms 6492 KB Output is correct
49 Correct 3 ms 6492 KB Output is correct
50 Correct 2 ms 6492 KB Output is correct
51 Correct 2 ms 6584 KB Output is correct
52 Correct 2 ms 6488 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 3 ms 6492 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 2 ms 6748 KB Output is correct
58 Correct 2 ms 6492 KB Output is correct
59 Correct 3 ms 6748 KB Output is correct
60 Correct 2 ms 6492 KB Output is correct
61 Correct 2 ms 6560 KB Output is correct
62 Correct 2 ms 6492 KB Output is correct
63 Correct 2 ms 6492 KB Output is correct
64 Correct 64 ms 16080 KB Output is correct
65 Correct 65 ms 16016 KB Output is correct
66 Correct 66 ms 16000 KB Output is correct
67 Correct 62 ms 16012 KB Output is correct
68 Correct 67 ms 16032 KB Output is correct
69 Correct 60 ms 16012 KB Output is correct
70 Correct 75 ms 16036 KB Output is correct
71 Correct 85 ms 16184 KB Output is correct
72 Correct 61 ms 16012 KB Output is correct
73 Correct 74 ms 26004 KB Output is correct
74 Correct 82 ms 26000 KB Output is correct
75 Correct 63 ms 16016 KB Output is correct
76 Correct 58 ms 15932 KB Output is correct
77 Correct 71 ms 16016 KB Output is correct
78 Correct 92 ms 16108 KB Output is correct
79 Correct 91 ms 15924 KB Output is correct
80 Correct 56 ms 15952 KB Output is correct
81 Correct 64 ms 16452 KB Output is correct
82 Correct 56 ms 16076 KB Output is correct
83 Correct 105 ms 20184 KB Output is correct
84 Correct 73 ms 21668 KB Output is correct
85 Correct 90 ms 21408 KB Output is correct
86 Correct 67 ms 16984 KB Output is correct
87 Correct 65 ms 16524 KB Output is correct
88 Correct 60 ms 17100 KB Output is correct
89 Correct 70 ms 17052 KB Output is correct
90 Correct 71 ms 16884 KB Output is correct
91 Correct 87 ms 17096 KB Output is correct
92 Correct 78 ms 17276 KB Output is correct
93 Correct 79 ms 19348 KB Output is correct
94 Correct 64 ms 20700 KB Output is correct
95 Correct 60 ms 19596 KB Output is correct
96 Correct 58 ms 18280 KB Output is correct
97 Correct 61 ms 16872 KB Output is correct
98 Correct 96 ms 16900 KB Output is correct
99 Correct 63 ms 16280 KB Output is correct
100 Correct 75 ms 19032 KB Output is correct
101 Correct 68 ms 17164 KB Output is correct
102 Correct 66 ms 16740 KB Output is correct
103 Correct 80 ms 16608 KB Output is correct
104 Correct 47 ms 16844 KB Output is correct
105 Correct 75 ms 23440 KB Output is correct
106 Correct 47 ms 16988 KB Output is correct
107 Correct 47 ms 16836 KB Output is correct
108 Correct 68 ms 26768 KB Output is correct
109 Correct 42 ms 17224 KB Output is correct
110 Correct 79 ms 27028 KB Output is correct
111 Correct 58 ms 15900 KB Output is correct