# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
530309 | 2022-02-25T03:35:46 Z | kevin | Power Plant (JOI20_power) | C++17 | 3 ms | 5016 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); if(val > 0) 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'; } dfs(0, -1); cout<<mx; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 5016 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 5016 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 5016 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |