답안 #1016141

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016141 2024-07-07T12:36:08 Z ByeWorld Power Plant (JOI20_power) C++14
100 / 100
139 ms 32480 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
#define ll long long
// #define int long long
#define pb push_back
#define fi first
#define se second
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)/2)
#define ld long double
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii, int> ipii;
const int MAXN = 3e5+10;
const int MAXA = 1e6+10;
const int INF = 1e9+10;
// const int INF2 = 1e18+10;
const int LOG = 19;
const int MOD = 1e9+7;
const int SQRT = 450;
const vector<int> NOL = {};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const vector<int> dx = {1, -1, 0, 0};
const vector<int> dy = {0, 0, 1, -1};
void chmn(int &a, int b){ a = min(a, b); }
void chmx(int &a, int b){ a = max(a, b); }

int n, a[MAXN];
vector <int> adj[MAXN];

int te = 0, ANS = 0, val[MAXN];
void dfs(int nw, int par){
    val[nw] = 0;
    for(auto nx : adj[nw]){
        if(nx==par) continue;
        dfs(nx, nw);
    }
    int mx = 0;
    for(auto nx : adj[nw]){
        if(nx==par) continue;
        val[nw] += val[nx];
        chmx(mx, val[nx]);
    }
    if(a[nw]){
        val[nw] = max(val[nw]-1, 1);
        chmx(ANS, mx+1);
    }

    chmx(ANS, val[nw]);
}

signed main(){
    cin >> n;
    for(int i=1; i<=n-1; i++){
        int x, y; cin >> x >> y;
        adj[x].pb(y); adj[y].pb(x);
    }
    string x; cin >> x; int tot = 0;
    for(int i=1; i<=n; i++){
        a[i] = (int)(x[i-1]-'0'); tot += a[i];
    }

        dfs(1, 0); 
    cout << ANS << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 3 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 4 ms 7260 KB Output is correct
5 Correct 4 ms 7260 KB Output is correct
6 Correct 3 ms 7260 KB Output is correct
7 Correct 3 ms 7260 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 5 ms 7260 KB Output is correct
10 Correct 2 ms 8536 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 2 ms 8284 KB Output is correct
13 Correct 2 ms 8284 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 2 ms 8284 KB Output is correct
18 Correct 3 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 3 ms 8284 KB Output is correct
21 Correct 2 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 3 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 4 ms 7260 KB Output is correct
5 Correct 4 ms 7260 KB Output is correct
6 Correct 3 ms 7260 KB Output is correct
7 Correct 3 ms 7260 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 5 ms 7260 KB Output is correct
10 Correct 2 ms 8536 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 2 ms 8284 KB Output is correct
13 Correct 2 ms 8284 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 2 ms 8284 KB Output is correct
18 Correct 3 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 3 ms 8284 KB Output is correct
21 Correct 2 ms 8284 KB Output is correct
22 Correct 5 ms 8536 KB Output is correct
23 Correct 5 ms 8540 KB Output is correct
24 Correct 3 ms 8540 KB Output is correct
25 Correct 3 ms 8540 KB Output is correct
26 Correct 3 ms 8540 KB Output is correct
27 Correct 4 ms 8540 KB Output is correct
28 Correct 3 ms 8540 KB Output is correct
29 Correct 3 ms 8540 KB Output is correct
30 Correct 3 ms 8540 KB Output is correct
31 Correct 4 ms 8384 KB Output is correct
32 Correct 3 ms 8540 KB Output is correct
33 Correct 3 ms 8540 KB Output is correct
34 Correct 3 ms 8540 KB Output is correct
35 Correct 4 ms 8540 KB Output is correct
36 Correct 3 ms 8540 KB Output is correct
37 Correct 3 ms 8540 KB Output is correct
38 Correct 5 ms 8540 KB Output is correct
39 Correct 4 ms 8540 KB Output is correct
40 Correct 3 ms 8540 KB Output is correct
41 Correct 3 ms 8540 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 2 ms 8540 KB Output is correct
44 Correct 2 ms 8540 KB Output is correct
45 Correct 2 ms 8540 KB Output is correct
46 Correct 2 ms 8540 KB Output is correct
47 Correct 2 ms 8632 KB Output is correct
48 Correct 2 ms 8796 KB Output is correct
49 Correct 3 ms 8632 KB Output is correct
50 Correct 2 ms 8540 KB Output is correct
51 Correct 2 ms 8540 KB Output is correct
52 Correct 2 ms 8540 KB Output is correct
53 Correct 2 ms 8540 KB Output is correct
54 Correct 3 ms 8540 KB Output is correct
55 Correct 3 ms 8540 KB Output is correct
56 Correct 4 ms 8540 KB Output is correct
57 Correct 4 ms 8640 KB Output is correct
58 Correct 2 ms 8540 KB Output is correct
59 Correct 4 ms 8540 KB Output is correct
60 Correct 4 ms 8796 KB Output is correct
61 Correct 3 ms 8540 KB Output is correct
62 Correct 3 ms 8636 KB Output is correct
63 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 3 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 4 ms 7260 KB Output is correct
5 Correct 4 ms 7260 KB Output is correct
6 Correct 3 ms 7260 KB Output is correct
7 Correct 3 ms 7260 KB Output is correct
8 Correct 2 ms 8284 KB Output is correct
9 Correct 5 ms 7260 KB Output is correct
10 Correct 2 ms 8536 KB Output is correct
11 Correct 2 ms 8284 KB Output is correct
12 Correct 2 ms 8284 KB Output is correct
13 Correct 2 ms 8284 KB Output is correct
14 Correct 2 ms 8284 KB Output is correct
15 Correct 2 ms 8284 KB Output is correct
16 Correct 2 ms 8284 KB Output is correct
17 Correct 2 ms 8284 KB Output is correct
18 Correct 3 ms 8284 KB Output is correct
19 Correct 2 ms 8284 KB Output is correct
20 Correct 3 ms 8284 KB Output is correct
21 Correct 2 ms 8284 KB Output is correct
22 Correct 5 ms 8536 KB Output is correct
23 Correct 5 ms 8540 KB Output is correct
24 Correct 3 ms 8540 KB Output is correct
25 Correct 3 ms 8540 KB Output is correct
26 Correct 3 ms 8540 KB Output is correct
27 Correct 4 ms 8540 KB Output is correct
28 Correct 3 ms 8540 KB Output is correct
29 Correct 3 ms 8540 KB Output is correct
30 Correct 3 ms 8540 KB Output is correct
31 Correct 4 ms 8384 KB Output is correct
32 Correct 3 ms 8540 KB Output is correct
33 Correct 3 ms 8540 KB Output is correct
34 Correct 3 ms 8540 KB Output is correct
35 Correct 4 ms 8540 KB Output is correct
36 Correct 3 ms 8540 KB Output is correct
37 Correct 3 ms 8540 KB Output is correct
38 Correct 5 ms 8540 KB Output is correct
39 Correct 4 ms 8540 KB Output is correct
40 Correct 3 ms 8540 KB Output is correct
41 Correct 3 ms 8540 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 2 ms 8540 KB Output is correct
44 Correct 2 ms 8540 KB Output is correct
45 Correct 2 ms 8540 KB Output is correct
46 Correct 2 ms 8540 KB Output is correct
47 Correct 2 ms 8632 KB Output is correct
48 Correct 2 ms 8796 KB Output is correct
49 Correct 3 ms 8632 KB Output is correct
50 Correct 2 ms 8540 KB Output is correct
51 Correct 2 ms 8540 KB Output is correct
52 Correct 2 ms 8540 KB Output is correct
53 Correct 2 ms 8540 KB Output is correct
54 Correct 3 ms 8540 KB Output is correct
55 Correct 3 ms 8540 KB Output is correct
56 Correct 4 ms 8540 KB Output is correct
57 Correct 4 ms 8640 KB Output is correct
58 Correct 2 ms 8540 KB Output is correct
59 Correct 4 ms 8540 KB Output is correct
60 Correct 4 ms 8796 KB Output is correct
61 Correct 3 ms 8540 KB Output is correct
62 Correct 3 ms 8636 KB Output is correct
63 Correct 2 ms 8540 KB Output is correct
64 Correct 97 ms 16084 KB Output is correct
65 Correct 121 ms 18772 KB Output is correct
66 Correct 101 ms 18660 KB Output is correct
67 Correct 100 ms 18744 KB Output is correct
68 Correct 99 ms 18652 KB Output is correct
69 Correct 130 ms 18656 KB Output is correct
70 Correct 122 ms 18908 KB Output is correct
71 Correct 107 ms 18664 KB Output is correct
72 Correct 97 ms 18664 KB Output is correct
73 Correct 116 ms 31456 KB Output is correct
74 Correct 113 ms 31204 KB Output is correct
75 Correct 135 ms 18628 KB Output is correct
76 Correct 105 ms 18660 KB Output is correct
77 Correct 101 ms 18588 KB Output is correct
78 Correct 103 ms 18692 KB Output is correct
79 Correct 105 ms 18656 KB Output is correct
80 Correct 100 ms 18656 KB Output is correct
81 Correct 91 ms 19000 KB Output is correct
82 Correct 98 ms 19060 KB Output is correct
83 Correct 122 ms 23724 KB Output is correct
84 Correct 112 ms 26080 KB Output is correct
85 Correct 106 ms 25576 KB Output is correct
86 Correct 107 ms 20044 KB Output is correct
87 Correct 97 ms 19424 KB Output is correct
88 Correct 97 ms 19904 KB Output is correct
89 Correct 107 ms 19952 KB Output is correct
90 Correct 96 ms 19840 KB Output is correct
91 Correct 98 ms 19968 KB Output is correct
92 Correct 114 ms 20304 KB Output is correct
93 Correct 115 ms 22620 KB Output is correct
94 Correct 98 ms 24576 KB Output is correct
95 Correct 102 ms 23132 KB Output is correct
96 Correct 110 ms 21220 KB Output is correct
97 Correct 103 ms 19752 KB Output is correct
98 Correct 105 ms 19172 KB Output is correct
99 Correct 105 ms 19120 KB Output is correct
100 Correct 106 ms 22200 KB Output is correct
101 Correct 139 ms 20148 KB Output is correct
102 Correct 100 ms 19428 KB Output is correct
103 Correct 100 ms 19300 KB Output is correct
104 Correct 95 ms 19652 KB Output is correct
105 Correct 114 ms 28128 KB Output is correct
106 Correct 84 ms 19400 KB Output is correct
107 Correct 86 ms 19348 KB Output is correct
108 Correct 115 ms 32228 KB Output is correct
109 Correct 91 ms 19712 KB Output is correct
110 Correct 111 ms 32480 KB Output is correct
111 Correct 97 ms 18688 KB Output is correct