답안 #945959

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945959 2024-03-14T09:07:54 Z efedmrlr Power Plant (JOI20_power) C++17
100 / 100
217 ms 29264 KB
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>

using namespace std;


#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()


void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 3e5+5;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n,m,q;
vector<vector<int> > adj;
vector<int> isPow;
vector<int> dp;
int ans = 0;
void dfs(int node, int par) {
    int sum = 0;
    for(auto c : adj[node]) {
        if(c == par) continue;
        dfs(c, node);
        sum += dp[c];
    }
    dp[node] = max(isPow[node], sum - isPow[node]);
    if(isPow[node]) {
        for(auto c : adj[node]) {
            ans = max(ans, dp[c] + 1);
        }
    }
}

inline void solve() {
    cin>>n;
    adj.assign(n + 1, vector<int>());
    isPow.assign(n + 1, 0);
    dp.assign(n + 1, 0);
    REP(i, n - 1) {
        int a,b;
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    for(int i = 1; i <= n; i++) {
        char x;
        cin >> x;
        if(x == '1') isPow[i] = 1;
    }
    dfs(1, 0);
    ans = max(ans, dp[1]);
    cout << ans << "\n";
}
 
signed main() {

    //fastio();
    int test = 1;
    //cin>>test;
    while(test--) {
        solve();
    }
    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 436 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 436 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 448 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 612 KB Output is correct
30 Correct 1 ms 608 KB Output is correct
31 Correct 1 ms 444 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 448 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 600 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 1 ms 600 KB Output is correct
45 Correct 2 ms 600 KB Output is correct
46 Correct 1 ms 600 KB Output is correct
47 Correct 2 ms 344 KB Output is correct
48 Correct 1 ms 584 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 2 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 856 KB Output is correct
61 Correct 2 ms 604 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 1 ms 576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 436 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 448 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 612 KB Output is correct
30 Correct 1 ms 608 KB Output is correct
31 Correct 1 ms 444 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 448 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 600 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 1 ms 600 KB Output is correct
45 Correct 2 ms 600 KB Output is correct
46 Correct 1 ms 600 KB Output is correct
47 Correct 2 ms 344 KB Output is correct
48 Correct 1 ms 584 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 2 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 856 KB Output is correct
61 Correct 2 ms 604 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 1 ms 576 KB Output is correct
64 Correct 162 ms 15580 KB Output is correct
65 Correct 146 ms 15692 KB Output is correct
66 Correct 139 ms 15700 KB Output is correct
67 Correct 170 ms 15652 KB Output is correct
68 Correct 137 ms 15696 KB Output is correct
69 Correct 139 ms 15612 KB Output is correct
70 Correct 146 ms 15696 KB Output is correct
71 Correct 133 ms 15568 KB Output is correct
72 Correct 136 ms 15660 KB Output is correct
73 Correct 200 ms 28312 KB Output is correct
74 Correct 205 ms 28396 KB Output is correct
75 Correct 147 ms 15640 KB Output is correct
76 Correct 155 ms 15672 KB Output is correct
77 Correct 161 ms 15732 KB Output is correct
78 Correct 215 ms 15472 KB Output is correct
79 Correct 146 ms 15656 KB Output is correct
80 Correct 133 ms 15444 KB Output is correct
81 Correct 122 ms 15820 KB Output is correct
82 Correct 152 ms 15824 KB Output is correct
83 Correct 191 ms 20816 KB Output is correct
84 Correct 216 ms 22784 KB Output is correct
85 Correct 150 ms 22608 KB Output is correct
86 Correct 154 ms 16980 KB Output is correct
87 Correct 180 ms 16720 KB Output is correct
88 Correct 143 ms 16872 KB Output is correct
89 Correct 162 ms 16980 KB Output is correct
90 Correct 147 ms 16724 KB Output is correct
91 Correct 142 ms 16980 KB Output is correct
92 Correct 162 ms 17236 KB Output is correct
93 Correct 132 ms 19660 KB Output is correct
94 Correct 167 ms 21412 KB Output is correct
95 Correct 148 ms 20040 KB Output is correct
96 Correct 146 ms 18624 KB Output is correct
97 Correct 154 ms 16724 KB Output is correct
98 Correct 130 ms 16136 KB Output is correct
99 Correct 154 ms 16136 KB Output is correct
100 Correct 152 ms 19296 KB Output is correct
101 Correct 177 ms 17388 KB Output is correct
102 Correct 186 ms 16432 KB Output is correct
103 Correct 142 ms 16216 KB Output is correct
104 Correct 117 ms 16348 KB Output is correct
105 Correct 181 ms 25084 KB Output is correct
106 Correct 109 ms 16328 KB Output is correct
107 Correct 122 ms 16168 KB Output is correct
108 Correct 217 ms 29052 KB Output is correct
109 Correct 117 ms 16332 KB Output is correct
110 Correct 163 ms 29264 KB Output is correct
111 Correct 131 ms 15444 KB Output is correct