Submission #788017

#TimeUsernameProblemLanguageResultExecution timeMemory
788017YassineBenYounesPower Plant (JOI20_power)C++17
100 / 100
196 ms30300 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define vi vector<int> #define pii pair<int, int> #define ff first #define ss second #define vii vector<pii> void init(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // ONLINE_JUDGE } const int mx = 3e5+5; const ll mod = 1e9+7; vector<int> graph[mx]; string s; int dp_down[mx]; int ans = 0; void dfs(int node, int p){ int l = 0, sum = 0; for(int adj : graph[node]){ if(adj == p)continue; dfs(adj ,node); sum += dp_down[adj]; l = max(l, dp_down[adj]); } int k = (s[node] == '1'); sum -= k; dp_down[node] = max(dp_down[node], k); dp_down[node] = max(dp_down[node], sum); ans = max(ans, l+k); ans = max(ans, dp_down[node]); } void runcase(){ int n;cin >> n; for(int i = 0; i < n-1;i++){ int a, b;cin >> a >> b; graph[a].pb(b); graph[b].pb(a); } cin >> s; s = "Y" + s; dfs(1, 1); cout << ans << endl; } int main(){ int t; //cin >> t; t = 1; while(t--){ runcase(); } }

Compilation message (stderr)

power.cpp: In function 'void init()':
power.cpp:14:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
power.cpp:16:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | freopen("output.txt", "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...