답안 #1098070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098070 2024-10-09T03:05:08 Z TrinhKhanhDung Power Plant (JOI20_power) C++14
100 / 100
77 ms 28880 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

const int MAX = 2e5 + 10;

int N, ans;
vector<int> adj[MAX];
int f[MAX];
string s;

void dfs(int u, int p = -1){
    int sum = 0;
    int ma = 0;
    for(int v: adj[u]){
        if(v == p) continue;
        dfs(v, u);
        sum += f[v];
        maximize(ma, f[v]);
    }
    f[u] = max((int)(s[u] == '1'), sum - (s[u] == '1'));
    maximize(ans, sum - (s[u] == '1'));
    maximize(ans, ma + (s[u] == '1'));
//    cout << u << ' ' << f[u] << '\n';
}

void solve(){
    cin >> N;
    for(int i = 1; i < N; i++){
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    cin >> s;
    s = "*" + s;
    dfs(1);
    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
//     freopen("btower.inp","r",stdin);
//     freopen("btower.out","w",stdout);

    int t = 1;
//    cin >> t;
    while(t--){
        solve();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 5080 KB Output is correct
7 Correct 2 ms 4952 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 5080 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4952 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 5080 KB Output is correct
7 Correct 2 ms 4952 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 5080 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4952 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 5208 KB Output is correct
23 Correct 3 ms 5212 KB Output is correct
24 Correct 2 ms 5212 KB Output is correct
25 Correct 2 ms 5212 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 2 ms 5168 KB Output is correct
28 Correct 2 ms 5208 KB Output is correct
29 Correct 3 ms 5212 KB Output is correct
30 Correct 3 ms 5336 KB Output is correct
31 Correct 3 ms 5212 KB Output is correct
32 Correct 2 ms 5212 KB Output is correct
33 Correct 3 ms 5256 KB Output is correct
34 Correct 3 ms 5212 KB Output is correct
35 Correct 2 ms 5228 KB Output is correct
36 Correct 2 ms 5212 KB Output is correct
37 Correct 3 ms 5212 KB Output is correct
38 Correct 3 ms 5212 KB Output is correct
39 Correct 3 ms 5212 KB Output is correct
40 Correct 3 ms 5240 KB Output is correct
41 Correct 2 ms 5152 KB Output is correct
42 Correct 3 ms 5212 KB Output is correct
43 Correct 2 ms 5212 KB Output is correct
44 Correct 2 ms 5212 KB Output is correct
45 Correct 2 ms 5212 KB Output is correct
46 Correct 2 ms 5212 KB Output is correct
47 Correct 2 ms 5212 KB Output is correct
48 Correct 2 ms 5212 KB Output is correct
49 Correct 2 ms 5212 KB Output is correct
50 Correct 2 ms 5212 KB Output is correct
51 Correct 3 ms 5212 KB Output is correct
52 Correct 2 ms 5212 KB Output is correct
53 Correct 3 ms 5212 KB Output is correct
54 Correct 3 ms 5248 KB Output is correct
55 Correct 3 ms 5212 KB Output is correct
56 Correct 3 ms 5168 KB Output is correct
57 Correct 3 ms 5172 KB Output is correct
58 Correct 2 ms 5476 KB Output is correct
59 Correct 3 ms 5212 KB Output is correct
60 Correct 3 ms 5212 KB Output is correct
61 Correct 3 ms 5244 KB Output is correct
62 Correct 3 ms 5212 KB Output is correct
63 Correct 2 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 5080 KB Output is correct
7 Correct 2 ms 4952 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 5080 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4952 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 5208 KB Output is correct
23 Correct 3 ms 5212 KB Output is correct
24 Correct 2 ms 5212 KB Output is correct
25 Correct 2 ms 5212 KB Output is correct
26 Correct 2 ms 5212 KB Output is correct
27 Correct 2 ms 5168 KB Output is correct
28 Correct 2 ms 5208 KB Output is correct
29 Correct 3 ms 5212 KB Output is correct
30 Correct 3 ms 5336 KB Output is correct
31 Correct 3 ms 5212 KB Output is correct
32 Correct 2 ms 5212 KB Output is correct
33 Correct 3 ms 5256 KB Output is correct
34 Correct 3 ms 5212 KB Output is correct
35 Correct 2 ms 5228 KB Output is correct
36 Correct 2 ms 5212 KB Output is correct
37 Correct 3 ms 5212 KB Output is correct
38 Correct 3 ms 5212 KB Output is correct
39 Correct 3 ms 5212 KB Output is correct
40 Correct 3 ms 5240 KB Output is correct
41 Correct 2 ms 5152 KB Output is correct
42 Correct 3 ms 5212 KB Output is correct
43 Correct 2 ms 5212 KB Output is correct
44 Correct 2 ms 5212 KB Output is correct
45 Correct 2 ms 5212 KB Output is correct
46 Correct 2 ms 5212 KB Output is correct
47 Correct 2 ms 5212 KB Output is correct
48 Correct 2 ms 5212 KB Output is correct
49 Correct 2 ms 5212 KB Output is correct
50 Correct 2 ms 5212 KB Output is correct
51 Correct 3 ms 5212 KB Output is correct
52 Correct 2 ms 5212 KB Output is correct
53 Correct 3 ms 5212 KB Output is correct
54 Correct 3 ms 5248 KB Output is correct
55 Correct 3 ms 5212 KB Output is correct
56 Correct 3 ms 5168 KB Output is correct
57 Correct 3 ms 5172 KB Output is correct
58 Correct 2 ms 5476 KB Output is correct
59 Correct 3 ms 5212 KB Output is correct
60 Correct 3 ms 5212 KB Output is correct
61 Correct 3 ms 5244 KB Output is correct
62 Correct 3 ms 5212 KB Output is correct
63 Correct 2 ms 5212 KB Output is correct
64 Correct 58 ms 15312 KB Output is correct
65 Correct 55 ms 15152 KB Output is correct
66 Correct 55 ms 15288 KB Output is correct
67 Correct 60 ms 15312 KB Output is correct
68 Correct 60 ms 15276 KB Output is correct
69 Correct 55 ms 15304 KB Output is correct
70 Correct 54 ms 15248 KB Output is correct
71 Correct 54 ms 15184 KB Output is correct
72 Correct 69 ms 15304 KB Output is correct
73 Correct 73 ms 27796 KB Output is correct
74 Correct 72 ms 27696 KB Output is correct
75 Correct 65 ms 15052 KB Output is correct
76 Correct 68 ms 15240 KB Output is correct
77 Correct 62 ms 15048 KB Output is correct
78 Correct 61 ms 15056 KB Output is correct
79 Correct 63 ms 15048 KB Output is correct
80 Correct 70 ms 15048 KB Output is correct
81 Correct 51 ms 15596 KB Output is correct
82 Correct 62 ms 15188 KB Output is correct
83 Correct 66 ms 20432 KB Output is correct
84 Correct 61 ms 22476 KB Output is correct
85 Correct 65 ms 22236 KB Output is correct
86 Correct 60 ms 16456 KB Output is correct
87 Correct 56 ms 16076 KB Output is correct
88 Correct 56 ms 16396 KB Output is correct
89 Correct 60 ms 16576 KB Output is correct
90 Correct 56 ms 16280 KB Output is correct
91 Correct 62 ms 16564 KB Output is correct
92 Correct 59 ms 16828 KB Output is correct
93 Correct 55 ms 19104 KB Output is correct
94 Correct 56 ms 20876 KB Output is correct
95 Correct 53 ms 19592 KB Output is correct
96 Correct 53 ms 17720 KB Output is correct
97 Correct 55 ms 16284 KB Output is correct
98 Correct 52 ms 15864 KB Output is correct
99 Correct 52 ms 15564 KB Output is correct
100 Correct 55 ms 18872 KB Output is correct
101 Correct 76 ms 16716 KB Output is correct
102 Correct 51 ms 16032 KB Output is correct
103 Correct 61 ms 15724 KB Output is correct
104 Correct 43 ms 16040 KB Output is correct
105 Correct 71 ms 24528 KB Output is correct
106 Correct 44 ms 16032 KB Output is correct
107 Correct 49 ms 16068 KB Output is correct
108 Correct 77 ms 28592 KB Output is correct
109 Correct 41 ms 16080 KB Output is correct
110 Correct 75 ms 28880 KB Output is correct
111 Correct 57 ms 15324 KB Output is correct