답안 #313081

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313081 2020-10-15T07:34:02 Z Jarif_Rahman Power Plant (JOI20_power) C++17
47 / 100
1500 ms 14652 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n;
str s;
vector <vector<int>> v;
ll ans =  0;
int snd;
ll dfs(int nd, int ss){
    ll r = '0'-s[nd];
    bool bl = (r==-1);
    ll mx = 0;
    if(ss == -1 && v[nd].size() == 1) r = 1;
    for(int x: v[nd]) if(x != ss){
        ll y = dfs(x, nd);
        mx = max(mx, y);
        r+=y;
    }
    if(bl && nd == snd) r = max(r, mx+1);
    return max(r, (ll)s[nd] - '0');
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    v = vector<vector<int>> (n+1);
    for(int i = 1; i < n; i++){
        int a, b; cin >> a >> b;
        v[a].pb(b);
        v[b].pb(a);
    }
    cin >> s;
    s = "x"+s;
    for(int i = 1; i <= n; i++) if(s[i] == '1'){
        snd = i;
        ans = max(ans, dfs(i, -1));
    }
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 80 ms 512 KB Output is correct
23 Correct 71 ms 512 KB Output is correct
24 Correct 59 ms 512 KB Output is correct
25 Correct 38 ms 512 KB Output is correct
26 Correct 20 ms 512 KB Output is correct
27 Correct 9 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 98 ms 760 KB Output is correct
30 Correct 55 ms 640 KB Output is correct
31 Correct 68 ms 512 KB Output is correct
32 Correct 37 ms 512 KB Output is correct
33 Correct 72 ms 512 KB Output is correct
34 Correct 41 ms 512 KB Output is correct
35 Correct 20 ms 512 KB Output is correct
36 Correct 9 ms 512 KB Output is correct
37 Correct 50 ms 512 KB Output is correct
38 Correct 38 ms 512 KB Output is correct
39 Correct 93 ms 512 KB Output is correct
40 Correct 46 ms 512 KB Output is correct
41 Correct 22 ms 512 KB Output is correct
42 Correct 43 ms 512 KB Output is correct
43 Correct 9 ms 512 KB Output is correct
44 Correct 70 ms 512 KB Output is correct
45 Correct 56 ms 512 KB Output is correct
46 Correct 38 ms 512 KB Output is correct
47 Correct 19 ms 512 KB Output is correct
48 Correct 69 ms 512 KB Output is correct
49 Correct 69 ms 512 KB Output is correct
50 Correct 69 ms 512 KB Output is correct
51 Correct 71 ms 552 KB Output is correct
52 Correct 68 ms 532 KB Output is correct
53 Correct 52 ms 512 KB Output is correct
54 Correct 67 ms 512 KB Output is correct
55 Correct 71 ms 512 KB Output is correct
56 Correct 1 ms 512 KB Output is correct
57 Correct 2 ms 640 KB Output is correct
58 Correct 35 ms 512 KB Output is correct
59 Correct 37 ms 512 KB Output is correct
60 Correct 2 ms 640 KB Output is correct
61 Correct 1 ms 512 KB Output is correct
62 Correct 2 ms 640 KB Output is correct
63 Correct 59 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 80 ms 512 KB Output is correct
23 Correct 71 ms 512 KB Output is correct
24 Correct 59 ms 512 KB Output is correct
25 Correct 38 ms 512 KB Output is correct
26 Correct 20 ms 512 KB Output is correct
27 Correct 9 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 98 ms 760 KB Output is correct
30 Correct 55 ms 640 KB Output is correct
31 Correct 68 ms 512 KB Output is correct
32 Correct 37 ms 512 KB Output is correct
33 Correct 72 ms 512 KB Output is correct
34 Correct 41 ms 512 KB Output is correct
35 Correct 20 ms 512 KB Output is correct
36 Correct 9 ms 512 KB Output is correct
37 Correct 50 ms 512 KB Output is correct
38 Correct 38 ms 512 KB Output is correct
39 Correct 93 ms 512 KB Output is correct
40 Correct 46 ms 512 KB Output is correct
41 Correct 22 ms 512 KB Output is correct
42 Correct 43 ms 512 KB Output is correct
43 Correct 9 ms 512 KB Output is correct
44 Correct 70 ms 512 KB Output is correct
45 Correct 56 ms 512 KB Output is correct
46 Correct 38 ms 512 KB Output is correct
47 Correct 19 ms 512 KB Output is correct
48 Correct 69 ms 512 KB Output is correct
49 Correct 69 ms 512 KB Output is correct
50 Correct 69 ms 512 KB Output is correct
51 Correct 71 ms 552 KB Output is correct
52 Correct 68 ms 532 KB Output is correct
53 Correct 52 ms 512 KB Output is correct
54 Correct 67 ms 512 KB Output is correct
55 Correct 71 ms 512 KB Output is correct
56 Correct 1 ms 512 KB Output is correct
57 Correct 2 ms 640 KB Output is correct
58 Correct 35 ms 512 KB Output is correct
59 Correct 37 ms 512 KB Output is correct
60 Correct 2 ms 640 KB Output is correct
61 Correct 1 ms 512 KB Output is correct
62 Correct 2 ms 640 KB Output is correct
63 Correct 59 ms 632 KB Output is correct
64 Execution timed out 1589 ms 14652 KB Time limit exceeded
65 Halted 0 ms 0 KB -