답안 #992583

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
992583 2024-06-04T17:51:09 Z vyshniak_n Power Plant (JOI20_power) C++17
100 / 100
99 ms 29772 KB
//#pragma optimize("Ofast")
//#pragma optimize("unroll-loops")
//#pragma traget("avx,avx2")

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define el '\n'
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define point pair <ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

#include <random>
mt19937 rnd(time(0));

const ll INF = 1e18 + 10;
const ll inf = 1e9 + 10;
const ll N = 2e5 + 10;
const ll mod = 1e9 + 7;
const ll K = 7e6 + 100;
const ll LOG = 20;

vector <ll> gr[N];
string s;
ll dp[N], ans = 1;

void dfs(ll v, ll pr) {
    if (s[v] == '1')
        dp[v] = 1;

    ll sum = 0, mx = 0;
    for (ll to : gr[v]) {
        if (to == pr)
            continue;

        dfs(to, v);
        sum += dp[to];
        mx = max(mx, dp[to]);
    }

    if (s[v] == '1')
        sum--, ans = max(ans, mx + 1);
    dp[v] = max(dp[v], sum);
    ans = max(ans, dp[v]);
}

void solve() {
    ll n;
    cin >> n;

    for (ll i = 1; i < n; i++) {
        ll u, v;
        cin >> u >> v;

        gr[u].pb(v);
        gr[v].pb(u);
    }

    cin >> s;
    s = '#' + s;

    dfs(1, 1);
    cout << ans << el;
    return;
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int tests = 1;
    //cin >> tests;

    while (tests--) 
        solve();
    return 0;
}
/*
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6552 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6552 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 1 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 6332 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 1 ms 6492 KB Output is correct
14 Correct 2 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 6496 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 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6552 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6552 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 1 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 6332 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 1 ms 6492 KB Output is correct
14 Correct 2 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 6496 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 6488 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 3 ms 6564 KB Output is correct
25 Correct 3 ms 6492 KB Output is correct
26 Correct 3 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 3 ms 6560 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 3 ms 6528 KB Output is correct
31 Correct 2 ms 6776 KB Output is correct
32 Correct 2 ms 6496 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6500 KB Output is correct
35 Correct 2 ms 6488 KB Output is correct
36 Correct 3 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 6492 KB Output is correct
40 Correct 4 ms 6488 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 3 ms 6492 KB Output is correct
45 Correct 3 ms 6744 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 2 ms 6640 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 6492 KB Output is correct
52 Correct 3 ms 6496 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 3 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 2 ms 6744 KB Output is correct
58 Correct 3 ms 6488 KB Output is correct
59 Correct 3 ms 6488 KB Output is correct
60 Correct 2 ms 6492 KB Output is correct
61 Correct 2 ms 6492 KB Output is correct
62 Correct 2 ms 6748 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 6552 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6552 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 1 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 6332 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 1 ms 6492 KB Output is correct
14 Correct 2 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 6496 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 6488 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 3 ms 6564 KB Output is correct
25 Correct 3 ms 6492 KB Output is correct
26 Correct 3 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 3 ms 6560 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 3 ms 6528 KB Output is correct
31 Correct 2 ms 6776 KB Output is correct
32 Correct 2 ms 6496 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6500 KB Output is correct
35 Correct 2 ms 6488 KB Output is correct
36 Correct 3 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 6492 KB Output is correct
40 Correct 4 ms 6488 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6492 KB Output is correct
43 Correct 2 ms 6492 KB Output is correct
44 Correct 3 ms 6492 KB Output is correct
45 Correct 3 ms 6744 KB Output is correct
46 Correct 2 ms 6492 KB Output is correct
47 Correct 2 ms 6492 KB Output is correct
48 Correct 2 ms 6640 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 6492 KB Output is correct
52 Correct 3 ms 6496 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 3 ms 6492 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 2 ms 6744 KB Output is correct
58 Correct 3 ms 6488 KB Output is correct
59 Correct 3 ms 6488 KB Output is correct
60 Correct 2 ms 6492 KB Output is correct
61 Correct 2 ms 6492 KB Output is correct
62 Correct 2 ms 6748 KB Output is correct
63 Correct 2 ms 6492 KB Output is correct
64 Correct 66 ms 17048 KB Output is correct
65 Correct 58 ms 17044 KB Output is correct
66 Correct 75 ms 17084 KB Output is correct
67 Correct 59 ms 17040 KB Output is correct
68 Correct 64 ms 17068 KB Output is correct
69 Correct 76 ms 17004 KB Output is correct
70 Correct 62 ms 16964 KB Output is correct
71 Correct 64 ms 17104 KB Output is correct
72 Correct 61 ms 17100 KB Output is correct
73 Correct 67 ms 28620 KB Output is correct
74 Correct 75 ms 28496 KB Output is correct
75 Correct 59 ms 18288 KB Output is correct
76 Correct 64 ms 18324 KB Output is correct
77 Correct 57 ms 17032 KB Output is correct
78 Correct 61 ms 17040 KB Output is correct
79 Correct 63 ms 17056 KB Output is correct
80 Correct 90 ms 17080 KB Output is correct
81 Correct 62 ms 17092 KB Output is correct
82 Correct 53 ms 16904 KB Output is correct
83 Correct 92 ms 21968 KB Output is correct
84 Correct 69 ms 24284 KB Output is correct
85 Correct 62 ms 23916 KB Output is correct
86 Correct 66 ms 18388 KB Output is correct
87 Correct 81 ms 17612 KB Output is correct
88 Correct 57 ms 17924 KB Output is correct
89 Correct 65 ms 17956 KB Output is correct
90 Correct 76 ms 17644 KB Output is correct
91 Correct 60 ms 17780 KB Output is correct
92 Correct 68 ms 18108 KB Output is correct
93 Correct 67 ms 20428 KB Output is correct
94 Correct 98 ms 22184 KB Output is correct
95 Correct 98 ms 20736 KB Output is correct
96 Correct 99 ms 18976 KB Output is correct
97 Correct 63 ms 17592 KB Output is correct
98 Correct 54 ms 17148 KB Output is correct
99 Correct 71 ms 17100 KB Output is correct
100 Correct 69 ms 19960 KB Output is correct
101 Correct 83 ms 17960 KB Output is correct
102 Correct 57 ms 17308 KB Output is correct
103 Correct 74 ms 17392 KB Output is correct
104 Correct 79 ms 17584 KB Output is correct
105 Correct 75 ms 25316 KB Output is correct
106 Correct 58 ms 17596 KB Output is correct
107 Correct 49 ms 17500 KB Output is correct
108 Correct 89 ms 29464 KB Output is correct
109 Correct 57 ms 17548 KB Output is correct
110 Correct 77 ms 29772 KB Output is correct
111 Correct 58 ms 17052 KB Output is correct