Submission #530316

# Submission time Handle Problem Language Result Execution time Memory
530316 2022-02-25T03:51:19 Z kevin Power Plant (JOI20_power) C++17
100 / 100
142 ms 28528 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define nl cout<<"\n"
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define ca(v) for(auto i:v) cout<<i<<" ";
 
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
 
vector<int> adj[MAXN];
int ar[MAXN];
 
int mx = 0;
 
int dfs(int x, int p){
    int sm = 0;
    for(int i:adj[x]){
        if(i == p) continue;
        int val = dfs(i, x);
        sm += val;
        if(ar[x]) mx = max(mx, 1 + val);
    }
    if(ar[x]) {
        // cout<<x+1<<" "<<max(sm-1, 1)<<"\n";
        mx = max(mx, sm - 1);
        return max(sm-1, 1);
    }
    // cout<<x+1<<" "<<sm<<"\n";
    mx = max(mx, sm);
    return sm;
}
 
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) freopen("input.in", "r", stdin);
    int n;
    cin>>n;
    for(int i=0; i<n-1; i++){
        int u, v; cin>>u>>v;
        adj[--u].push_back(--v);
        adj[v].push_back(u);
    }
    for(int i=0; i<n; i++){
        char c; cin>>c;
        ar[i] = c == '1';
        if(ar[i]) mx = 1;
    }
    dfs(0, -1);
    cout<<mx;
}

Compilation message

power.cpp: In function 'int main()':
power.cpp:40:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     if (fopen("input.in", "r")) freopen("input.in", "r", stdin);
      |                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 3 ms 5016 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5020 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 5016 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 2 ms 5020 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 2 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 3 ms 5016 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5020 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 5016 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 2 ms 5020 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 2 ms 4940 KB Output is correct
22 Correct 3 ms 5020 KB Output is correct
23 Correct 3 ms 5068 KB Output is correct
24 Correct 3 ms 5068 KB Output is correct
25 Correct 3 ms 5068 KB Output is correct
26 Correct 3 ms 5068 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5024 KB Output is correct
29 Correct 3 ms 5156 KB Output is correct
30 Correct 3 ms 5156 KB Output is correct
31 Correct 3 ms 5028 KB Output is correct
32 Correct 4 ms 5068 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 4 ms 5024 KB Output is correct
35 Correct 3 ms 5068 KB Output is correct
36 Correct 3 ms 5028 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 4 ms 5024 KB Output is correct
39 Correct 3 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 3 ms 5068 KB Output is correct
42 Correct 3 ms 5068 KB Output is correct
43 Correct 3 ms 5028 KB Output is correct
44 Correct 4 ms 5068 KB Output is correct
45 Correct 3 ms 5068 KB Output is correct
46 Correct 3 ms 5068 KB Output is correct
47 Correct 3 ms 5068 KB Output is correct
48 Correct 4 ms 5068 KB Output is correct
49 Correct 3 ms 5196 KB Output is correct
50 Correct 3 ms 5068 KB Output is correct
51 Correct 3 ms 5024 KB Output is correct
52 Correct 3 ms 5032 KB Output is correct
53 Correct 3 ms 5068 KB Output is correct
54 Correct 3 ms 5080 KB Output is correct
55 Correct 3 ms 5068 KB Output is correct
56 Correct 3 ms 5068 KB Output is correct
57 Correct 4 ms 5156 KB Output is correct
58 Correct 3 ms 5068 KB Output is correct
59 Correct 3 ms 5068 KB Output is correct
60 Correct 3 ms 5068 KB Output is correct
61 Correct 3 ms 5068 KB Output is correct
62 Correct 3 ms 5148 KB Output is correct
63 Correct 3 ms 5024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 2 ms 4940 KB Output is correct
8 Correct 3 ms 5016 KB Output is correct
9 Correct 2 ms 4940 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5020 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 5016 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 2 ms 5020 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 2 ms 4940 KB Output is correct
22 Correct 3 ms 5020 KB Output is correct
23 Correct 3 ms 5068 KB Output is correct
24 Correct 3 ms 5068 KB Output is correct
25 Correct 3 ms 5068 KB Output is correct
26 Correct 3 ms 5068 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5024 KB Output is correct
29 Correct 3 ms 5156 KB Output is correct
30 Correct 3 ms 5156 KB Output is correct
31 Correct 3 ms 5028 KB Output is correct
32 Correct 4 ms 5068 KB Output is correct
33 Correct 3 ms 5076 KB Output is correct
34 Correct 4 ms 5024 KB Output is correct
35 Correct 3 ms 5068 KB Output is correct
36 Correct 3 ms 5028 KB Output is correct
37 Correct 3 ms 5068 KB Output is correct
38 Correct 4 ms 5024 KB Output is correct
39 Correct 3 ms 5068 KB Output is correct
40 Correct 3 ms 5068 KB Output is correct
41 Correct 3 ms 5068 KB Output is correct
42 Correct 3 ms 5068 KB Output is correct
43 Correct 3 ms 5028 KB Output is correct
44 Correct 4 ms 5068 KB Output is correct
45 Correct 3 ms 5068 KB Output is correct
46 Correct 3 ms 5068 KB Output is correct
47 Correct 3 ms 5068 KB Output is correct
48 Correct 4 ms 5068 KB Output is correct
49 Correct 3 ms 5196 KB Output is correct
50 Correct 3 ms 5068 KB Output is correct
51 Correct 3 ms 5024 KB Output is correct
52 Correct 3 ms 5032 KB Output is correct
53 Correct 3 ms 5068 KB Output is correct
54 Correct 3 ms 5080 KB Output is correct
55 Correct 3 ms 5068 KB Output is correct
56 Correct 3 ms 5068 KB Output is correct
57 Correct 4 ms 5156 KB Output is correct
58 Correct 3 ms 5068 KB Output is correct
59 Correct 3 ms 5068 KB Output is correct
60 Correct 3 ms 5068 KB Output is correct
61 Correct 3 ms 5068 KB Output is correct
62 Correct 3 ms 5148 KB Output is correct
63 Correct 3 ms 5024 KB Output is correct
64 Correct 111 ms 14844 KB Output is correct
65 Correct 111 ms 14760 KB Output is correct
66 Correct 110 ms 14896 KB Output is correct
67 Correct 102 ms 14748 KB Output is correct
68 Correct 119 ms 14860 KB Output is correct
69 Correct 102 ms 14788 KB Output is correct
70 Correct 100 ms 14756 KB Output is correct
71 Correct 108 ms 14864 KB Output is correct
72 Correct 127 ms 14964 KB Output is correct
73 Correct 123 ms 27452 KB Output is correct
74 Correct 142 ms 27332 KB Output is correct
75 Correct 102 ms 14700 KB Output is correct
76 Correct 102 ms 14696 KB Output is correct
77 Correct 108 ms 14748 KB Output is correct
78 Correct 113 ms 14704 KB Output is correct
79 Correct 112 ms 14708 KB Output is correct
80 Correct 100 ms 14724 KB Output is correct
81 Correct 89 ms 15036 KB Output is correct
82 Correct 100 ms 14948 KB Output is correct
83 Correct 115 ms 19908 KB Output is correct
84 Correct 122 ms 22096 KB Output is correct
85 Correct 116 ms 21676 KB Output is correct
86 Correct 110 ms 16104 KB Output is correct
87 Correct 107 ms 15508 KB Output is correct
88 Correct 103 ms 16080 KB Output is correct
89 Correct 112 ms 16180 KB Output is correct
90 Correct 108 ms 15840 KB Output is correct
91 Correct 111 ms 16072 KB Output is correct
92 Correct 111 ms 16360 KB Output is correct
93 Correct 102 ms 18752 KB Output is correct
94 Correct 104 ms 20380 KB Output is correct
95 Correct 92 ms 19204 KB Output is correct
96 Correct 103 ms 17376 KB Output is correct
97 Correct 119 ms 15848 KB Output is correct
98 Correct 101 ms 15408 KB Output is correct
99 Correct 105 ms 15172 KB Output is correct
100 Correct 103 ms 18372 KB Output is correct
101 Correct 101 ms 16356 KB Output is correct
102 Correct 104 ms 15528 KB Output is correct
103 Correct 108 ms 15408 KB Output is correct
104 Correct 64 ms 15552 KB Output is correct
105 Correct 132 ms 24208 KB Output is correct
106 Correct 60 ms 15416 KB Output is correct
107 Correct 64 ms 15412 KB Output is correct
108 Correct 133 ms 28312 KB Output is correct
109 Correct 62 ms 15604 KB Output is correct
110 Correct 120 ms 28528 KB Output is correct
111 Correct 97 ms 14660 KB Output is correct