Submission #530316

#TimeUsernameProblemLanguageResultExecution timeMemory
530316kevinPower Plant (JOI20_power)C++17
100 / 100
142 ms28528 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...