답안 #294001

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
294001 2020-09-08T14:20:11 Z muhammad_hokimiyon Power Plant (JOI20_power) C++14
100 / 100
209 ms 30968 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int N = 5e5 + 7;
const int M = 20 + 7;
const ll mod = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
int ans;
int a[N];
int d[N];
vector < int > v[N];

void dfs( int x , int p )
{
    vector < int > g;
    for( auto y : v[x] ){
        if( y == p )continue;
        dfs( y , x );
        d[x] += d[y];
    }
    if( a[x] ){
        d[x] -= 1;
        d[x] = max( d[x] , 1 );
    }
    if( x != p )ans = max( ans , d[x] + a[p] );
    ans = max( ans , d[x] );
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    cin >> n;
    for( int i = 1; i < n; i++ ){
        int x,y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for( int i = 1; i <= n; i++ ){
        char c;
        cin >> c;
        a[i] = c - '0';
    }
    dfs( 1 , 1 );
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12032 KB Output is correct
2 Correct 8 ms 12032 KB Output is correct
3 Correct 9 ms 12032 KB Output is correct
4 Correct 9 ms 12032 KB Output is correct
5 Correct 9 ms 12032 KB Output is correct
6 Correct 9 ms 12032 KB Output is correct
7 Correct 9 ms 12192 KB Output is correct
8 Correct 8 ms 12032 KB Output is correct
9 Correct 10 ms 12032 KB Output is correct
10 Correct 9 ms 12032 KB Output is correct
11 Correct 9 ms 12032 KB Output is correct
12 Correct 8 ms 12032 KB Output is correct
13 Correct 10 ms 12032 KB Output is correct
14 Correct 9 ms 12032 KB Output is correct
15 Correct 9 ms 12032 KB Output is correct
16 Correct 9 ms 12032 KB Output is correct
17 Correct 9 ms 12032 KB Output is correct
18 Correct 9 ms 12156 KB Output is correct
19 Correct 9 ms 12032 KB Output is correct
20 Correct 10 ms 12032 KB Output is correct
21 Correct 8 ms 12032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12032 KB Output is correct
2 Correct 8 ms 12032 KB Output is correct
3 Correct 9 ms 12032 KB Output is correct
4 Correct 9 ms 12032 KB Output is correct
5 Correct 9 ms 12032 KB Output is correct
6 Correct 9 ms 12032 KB Output is correct
7 Correct 9 ms 12192 KB Output is correct
8 Correct 8 ms 12032 KB Output is correct
9 Correct 10 ms 12032 KB Output is correct
10 Correct 9 ms 12032 KB Output is correct
11 Correct 9 ms 12032 KB Output is correct
12 Correct 8 ms 12032 KB Output is correct
13 Correct 10 ms 12032 KB Output is correct
14 Correct 9 ms 12032 KB Output is correct
15 Correct 9 ms 12032 KB Output is correct
16 Correct 9 ms 12032 KB Output is correct
17 Correct 9 ms 12032 KB Output is correct
18 Correct 9 ms 12156 KB Output is correct
19 Correct 9 ms 12032 KB Output is correct
20 Correct 10 ms 12032 KB Output is correct
21 Correct 8 ms 12032 KB Output is correct
22 Correct 10 ms 12160 KB Output is correct
23 Correct 11 ms 12160 KB Output is correct
24 Correct 9 ms 12160 KB Output is correct
25 Correct 11 ms 12160 KB Output is correct
26 Correct 12 ms 12160 KB Output is correct
27 Correct 11 ms 12160 KB Output is correct
28 Correct 10 ms 12160 KB Output is correct
29 Correct 10 ms 12288 KB Output is correct
30 Correct 9 ms 12288 KB Output is correct
31 Correct 9 ms 12160 KB Output is correct
32 Correct 9 ms 12160 KB Output is correct
33 Correct 10 ms 12160 KB Output is correct
34 Correct 10 ms 12160 KB Output is correct
35 Correct 10 ms 12288 KB Output is correct
36 Correct 9 ms 12160 KB Output is correct
37 Correct 9 ms 12160 KB Output is correct
38 Correct 11 ms 12160 KB Output is correct
39 Correct 9 ms 12160 KB Output is correct
40 Correct 11 ms 12160 KB Output is correct
41 Correct 12 ms 12160 KB Output is correct
42 Correct 9 ms 12160 KB Output is correct
43 Correct 10 ms 12160 KB Output is correct
44 Correct 9 ms 12160 KB Output is correct
45 Correct 9 ms 12160 KB Output is correct
46 Correct 11 ms 12160 KB Output is correct
47 Correct 9 ms 12160 KB Output is correct
48 Correct 9 ms 12288 KB Output is correct
49 Correct 9 ms 12288 KB Output is correct
50 Correct 10 ms 12160 KB Output is correct
51 Correct 10 ms 12160 KB Output is correct
52 Correct 9 ms 12160 KB Output is correct
53 Correct 9 ms 12160 KB Output is correct
54 Correct 11 ms 12160 KB Output is correct
55 Correct 10 ms 12160 KB Output is correct
56 Correct 10 ms 12160 KB Output is correct
57 Correct 9 ms 12320 KB Output is correct
58 Correct 9 ms 12160 KB Output is correct
59 Correct 9 ms 12160 KB Output is correct
60 Correct 9 ms 12288 KB Output is correct
61 Correct 9 ms 12160 KB Output is correct
62 Correct 9 ms 12288 KB Output is correct
63 Correct 10 ms 12160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12032 KB Output is correct
2 Correct 8 ms 12032 KB Output is correct
3 Correct 9 ms 12032 KB Output is correct
4 Correct 9 ms 12032 KB Output is correct
5 Correct 9 ms 12032 KB Output is correct
6 Correct 9 ms 12032 KB Output is correct
7 Correct 9 ms 12192 KB Output is correct
8 Correct 8 ms 12032 KB Output is correct
9 Correct 10 ms 12032 KB Output is correct
10 Correct 9 ms 12032 KB Output is correct
11 Correct 9 ms 12032 KB Output is correct
12 Correct 8 ms 12032 KB Output is correct
13 Correct 10 ms 12032 KB Output is correct
14 Correct 9 ms 12032 KB Output is correct
15 Correct 9 ms 12032 KB Output is correct
16 Correct 9 ms 12032 KB Output is correct
17 Correct 9 ms 12032 KB Output is correct
18 Correct 9 ms 12156 KB Output is correct
19 Correct 9 ms 12032 KB Output is correct
20 Correct 10 ms 12032 KB Output is correct
21 Correct 8 ms 12032 KB Output is correct
22 Correct 10 ms 12160 KB Output is correct
23 Correct 11 ms 12160 KB Output is correct
24 Correct 9 ms 12160 KB Output is correct
25 Correct 11 ms 12160 KB Output is correct
26 Correct 12 ms 12160 KB Output is correct
27 Correct 11 ms 12160 KB Output is correct
28 Correct 10 ms 12160 KB Output is correct
29 Correct 10 ms 12288 KB Output is correct
30 Correct 9 ms 12288 KB Output is correct
31 Correct 9 ms 12160 KB Output is correct
32 Correct 9 ms 12160 KB Output is correct
33 Correct 10 ms 12160 KB Output is correct
34 Correct 10 ms 12160 KB Output is correct
35 Correct 10 ms 12288 KB Output is correct
36 Correct 9 ms 12160 KB Output is correct
37 Correct 9 ms 12160 KB Output is correct
38 Correct 11 ms 12160 KB Output is correct
39 Correct 9 ms 12160 KB Output is correct
40 Correct 11 ms 12160 KB Output is correct
41 Correct 12 ms 12160 KB Output is correct
42 Correct 9 ms 12160 KB Output is correct
43 Correct 10 ms 12160 KB Output is correct
44 Correct 9 ms 12160 KB Output is correct
45 Correct 9 ms 12160 KB Output is correct
46 Correct 11 ms 12160 KB Output is correct
47 Correct 9 ms 12160 KB Output is correct
48 Correct 9 ms 12288 KB Output is correct
49 Correct 9 ms 12288 KB Output is correct
50 Correct 10 ms 12160 KB Output is correct
51 Correct 10 ms 12160 KB Output is correct
52 Correct 9 ms 12160 KB Output is correct
53 Correct 9 ms 12160 KB Output is correct
54 Correct 11 ms 12160 KB Output is correct
55 Correct 10 ms 12160 KB Output is correct
56 Correct 10 ms 12160 KB Output is correct
57 Correct 9 ms 12320 KB Output is correct
58 Correct 9 ms 12160 KB Output is correct
59 Correct 9 ms 12160 KB Output is correct
60 Correct 9 ms 12288 KB Output is correct
61 Correct 9 ms 12160 KB Output is correct
62 Correct 9 ms 12288 KB Output is correct
63 Correct 10 ms 12160 KB Output is correct
64 Correct 170 ms 19960 KB Output is correct
65 Correct 198 ms 19960 KB Output is correct
66 Correct 187 ms 19960 KB Output is correct
67 Correct 184 ms 19960 KB Output is correct
68 Correct 192 ms 20076 KB Output is correct
69 Correct 165 ms 19960 KB Output is correct
70 Correct 170 ms 20052 KB Output is correct
71 Correct 187 ms 19988 KB Output is correct
72 Correct 169 ms 20088 KB Output is correct
73 Correct 209 ms 30200 KB Output is correct
74 Correct 208 ms 30072 KB Output is correct
75 Correct 186 ms 19960 KB Output is correct
76 Correct 181 ms 19960 KB Output is correct
77 Correct 194 ms 19960 KB Output is correct
78 Correct 184 ms 19924 KB Output is correct
79 Correct 185 ms 19960 KB Output is correct
80 Correct 185 ms 20088 KB Output is correct
81 Correct 149 ms 20288 KB Output is correct
82 Correct 172 ms 20084 KB Output is correct
83 Correct 207 ms 24120 KB Output is correct
84 Correct 190 ms 25848 KB Output is correct
85 Correct 207 ms 25592 KB Output is correct
86 Correct 191 ms 21044 KB Output is correct
87 Correct 179 ms 20600 KB Output is correct
88 Correct 187 ms 21116 KB Output is correct
89 Correct 187 ms 21112 KB Output is correct
90 Correct 173 ms 20984 KB Output is correct
91 Correct 185 ms 21240 KB Output is correct
92 Correct 172 ms 21436 KB Output is correct
93 Correct 190 ms 23288 KB Output is correct
94 Correct 162 ms 24708 KB Output is correct
95 Correct 157 ms 23540 KB Output is correct
96 Correct 158 ms 22140 KB Output is correct
97 Correct 170 ms 20988 KB Output is correct
98 Correct 171 ms 20600 KB Output is correct
99 Correct 177 ms 20344 KB Output is correct
100 Correct 180 ms 23076 KB Output is correct
101 Correct 167 ms 21240 KB Output is correct
102 Correct 160 ms 20728 KB Output is correct
103 Correct 183 ms 20720 KB Output is correct
104 Correct 101 ms 19948 KB Output is correct
105 Correct 189 ms 27528 KB Output is correct
106 Correct 106 ms 20780 KB Output is correct
107 Correct 102 ms 20712 KB Output is correct
108 Correct 194 ms 30712 KB Output is correct
109 Correct 106 ms 19944 KB Output is correct
110 Correct 193 ms 30968 KB Output is correct
111 Correct 181 ms 19880 KB Output is correct