답안 #626553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626553 2022-08-11T14:25:30 Z NKIAMHAD Power Plant (JOI20_power) C++14
100 / 100
171 ms 39436 KB
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;
#define f first
#define s second
#define lid(x) (x*2)
#define rid(x) (1+x*2)
typedef pair<ll, ll> pii;
typedef pair<pii, ll> piii;
const ll maxn = 5e5+55;
const ll max2 = 1e6+55;
const ll inf = 1e9;
const ll lg = 17;
const ll base = 101;
const ll modn = 998244353;
const ll mod2 = 1e9+9;

ll T, len, que, num, sum, x, fir, sec;
vector <ll> G[maxn];
ll dp[maxn][2];
string s;

void dfs(ll x, ll last) {
    if(s[x-1] == '1') {
        ll sigma = 0, max0 = 0, max1 = 0;
        for(ll ver : G[x]) {
            if(ver == last)
                continue;
            dfs(ver, x);
            sigma += dp[ver][1], max0 = max(max0, dp[ver][0]), max1 = max(max1, dp[ver][1]);
        }
        dp[x][0] = max(1, max(sigma-1, max(max0, max1+1)));
        dp[x][1] = max(1, sigma-1);
        return;
    }
    ll sigma = 0, max0 = 0, max1 = 0;
    for(ll ver : G[x]) {
        if(ver == last)
            continue;
        dfs(ver, x);
        sigma += dp[ver][1], max0 = max(max0, dp[ver][0]), max1 = max(max1, dp[ver][1]);
    }
    dp[x][0] = max(max0, sigma);
    dp[x][1] = sigma;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> len;
    for(int i=1 ; i<len ; i++)
        cin >> fir >> sec, G[fir].pb(sec), G[sec].pb(fir);
    cin >> s;
    dfs(1, 0);
    cout << dp[1][0];


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11988 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 6 ms 12056 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 8 ms 12068 KB Output is correct
7 Correct 8 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 6 ms 12068 KB Output is correct
10 Correct 6 ms 11988 KB Output is correct
11 Correct 6 ms 12036 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12040 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 7 ms 11972 KB Output is correct
17 Correct 8 ms 11988 KB Output is correct
18 Correct 8 ms 11988 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 6 ms 11988 KB Output is correct
21 Correct 7 ms 11988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11988 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 6 ms 12056 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 8 ms 12068 KB Output is correct
7 Correct 8 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 6 ms 12068 KB Output is correct
10 Correct 6 ms 11988 KB Output is correct
11 Correct 6 ms 12036 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12040 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 7 ms 11972 KB Output is correct
17 Correct 8 ms 11988 KB Output is correct
18 Correct 8 ms 11988 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 6 ms 11988 KB Output is correct
21 Correct 7 ms 11988 KB Output is correct
22 Correct 8 ms 12148 KB Output is correct
23 Correct 7 ms 12116 KB Output is correct
24 Correct 7 ms 12116 KB Output is correct
25 Correct 7 ms 12088 KB Output is correct
26 Correct 8 ms 12084 KB Output is correct
27 Correct 7 ms 12084 KB Output is correct
28 Correct 7 ms 12080 KB Output is correct
29 Correct 7 ms 12244 KB Output is correct
30 Correct 7 ms 12152 KB Output is correct
31 Correct 7 ms 12088 KB Output is correct
32 Correct 7 ms 12116 KB Output is correct
33 Correct 7 ms 12084 KB Output is correct
34 Correct 8 ms 12128 KB Output is correct
35 Correct 7 ms 12080 KB Output is correct
36 Correct 7 ms 12116 KB Output is correct
37 Correct 7 ms 12116 KB Output is correct
38 Correct 7 ms 12116 KB Output is correct
39 Correct 7 ms 12212 KB Output is correct
40 Correct 7 ms 12116 KB Output is correct
41 Correct 7 ms 12208 KB Output is correct
42 Correct 7 ms 12116 KB Output is correct
43 Correct 7 ms 12084 KB Output is correct
44 Correct 7 ms 12116 KB Output is correct
45 Correct 7 ms 12084 KB Output is correct
46 Correct 7 ms 12116 KB Output is correct
47 Correct 8 ms 12116 KB Output is correct
48 Correct 8 ms 12232 KB Output is correct
49 Correct 7 ms 12244 KB Output is correct
50 Correct 9 ms 12116 KB Output is correct
51 Correct 7 ms 12116 KB Output is correct
52 Correct 7 ms 12116 KB Output is correct
53 Correct 7 ms 12116 KB Output is correct
54 Correct 7 ms 12088 KB Output is correct
55 Correct 7 ms 12116 KB Output is correct
56 Correct 7 ms 12116 KB Output is correct
57 Correct 7 ms 12244 KB Output is correct
58 Correct 8 ms 12116 KB Output is correct
59 Correct 7 ms 12116 KB Output is correct
60 Correct 7 ms 12244 KB Output is correct
61 Correct 8 ms 12116 KB Output is correct
62 Correct 7 ms 12264 KB Output is correct
63 Correct 7 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 11988 KB Output is correct
2 Correct 7 ms 11980 KB Output is correct
3 Correct 7 ms 11988 KB Output is correct
4 Correct 6 ms 12056 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 8 ms 12068 KB Output is correct
7 Correct 8 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 6 ms 12068 KB Output is correct
10 Correct 6 ms 11988 KB Output is correct
11 Correct 6 ms 12036 KB Output is correct
12 Correct 6 ms 11988 KB Output is correct
13 Correct 6 ms 12040 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
15 Correct 6 ms 11988 KB Output is correct
16 Correct 7 ms 11972 KB Output is correct
17 Correct 8 ms 11988 KB Output is correct
18 Correct 8 ms 11988 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 6 ms 11988 KB Output is correct
21 Correct 7 ms 11988 KB Output is correct
22 Correct 8 ms 12148 KB Output is correct
23 Correct 7 ms 12116 KB Output is correct
24 Correct 7 ms 12116 KB Output is correct
25 Correct 7 ms 12088 KB Output is correct
26 Correct 8 ms 12084 KB Output is correct
27 Correct 7 ms 12084 KB Output is correct
28 Correct 7 ms 12080 KB Output is correct
29 Correct 7 ms 12244 KB Output is correct
30 Correct 7 ms 12152 KB Output is correct
31 Correct 7 ms 12088 KB Output is correct
32 Correct 7 ms 12116 KB Output is correct
33 Correct 7 ms 12084 KB Output is correct
34 Correct 8 ms 12128 KB Output is correct
35 Correct 7 ms 12080 KB Output is correct
36 Correct 7 ms 12116 KB Output is correct
37 Correct 7 ms 12116 KB Output is correct
38 Correct 7 ms 12116 KB Output is correct
39 Correct 7 ms 12212 KB Output is correct
40 Correct 7 ms 12116 KB Output is correct
41 Correct 7 ms 12208 KB Output is correct
42 Correct 7 ms 12116 KB Output is correct
43 Correct 7 ms 12084 KB Output is correct
44 Correct 7 ms 12116 KB Output is correct
45 Correct 7 ms 12084 KB Output is correct
46 Correct 7 ms 12116 KB Output is correct
47 Correct 8 ms 12116 KB Output is correct
48 Correct 8 ms 12232 KB Output is correct
49 Correct 7 ms 12244 KB Output is correct
50 Correct 9 ms 12116 KB Output is correct
51 Correct 7 ms 12116 KB Output is correct
52 Correct 7 ms 12116 KB Output is correct
53 Correct 7 ms 12116 KB Output is correct
54 Correct 7 ms 12088 KB Output is correct
55 Correct 7 ms 12116 KB Output is correct
56 Correct 7 ms 12116 KB Output is correct
57 Correct 7 ms 12244 KB Output is correct
58 Correct 8 ms 12116 KB Output is correct
59 Correct 7 ms 12116 KB Output is correct
60 Correct 7 ms 12244 KB Output is correct
61 Correct 8 ms 12116 KB Output is correct
62 Correct 7 ms 12264 KB Output is correct
63 Correct 7 ms 12116 KB Output is correct
64 Correct 124 ms 22952 KB Output is correct
65 Correct 171 ms 23036 KB Output is correct
66 Correct 125 ms 22932 KB Output is correct
67 Correct 132 ms 23040 KB Output is correct
68 Correct 136 ms 22940 KB Output is correct
69 Correct 141 ms 23048 KB Output is correct
70 Correct 143 ms 23016 KB Output is correct
71 Correct 117 ms 23048 KB Output is correct
72 Correct 132 ms 22952 KB Output is correct
73 Correct 142 ms 38196 KB Output is correct
74 Correct 140 ms 38016 KB Output is correct
75 Correct 116 ms 22868 KB Output is correct
76 Correct 134 ms 22868 KB Output is correct
77 Correct 120 ms 22900 KB Output is correct
78 Correct 126 ms 22952 KB Output is correct
79 Correct 121 ms 22904 KB Output is correct
80 Correct 113 ms 22896 KB Output is correct
81 Correct 118 ms 23336 KB Output is correct
82 Correct 129 ms 23124 KB Output is correct
83 Correct 125 ms 29084 KB Output is correct
84 Correct 127 ms 31636 KB Output is correct
85 Correct 142 ms 31296 KB Output is correct
86 Correct 157 ms 24628 KB Output is correct
87 Correct 116 ms 23904 KB Output is correct
88 Correct 111 ms 24312 KB Output is correct
89 Correct 114 ms 24316 KB Output is correct
90 Correct 139 ms 24076 KB Output is correct
91 Correct 120 ms 24380 KB Output is correct
92 Correct 149 ms 24816 KB Output is correct
93 Correct 158 ms 27740 KB Output is correct
94 Correct 142 ms 29804 KB Output is correct
95 Correct 103 ms 28156 KB Output is correct
96 Correct 109 ms 26036 KB Output is correct
97 Correct 126 ms 24236 KB Output is correct
98 Correct 133 ms 23524 KB Output is correct
99 Correct 134 ms 23332 KB Output is correct
100 Correct 107 ms 27148 KB Output is correct
101 Correct 119 ms 24796 KB Output is correct
102 Correct 105 ms 23856 KB Output is correct
103 Correct 136 ms 23664 KB Output is correct
104 Correct 81 ms 23848 KB Output is correct
105 Correct 166 ms 34328 KB Output is correct
106 Correct 71 ms 23724 KB Output is correct
107 Correct 77 ms 23724 KB Output is correct
108 Correct 151 ms 39004 KB Output is correct
109 Correct 73 ms 23860 KB Output is correct
110 Correct 129 ms 39436 KB Output is correct
111 Correct 107 ms 22892 KB Output is correct