Submission #314271

#TimeUsernameProblemLanguageResultExecution timeMemory
314271mat_vPower Plant (JOI20_power)C++14
100 / 100
201 ms27704 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i)) #define mod 998244353 #define xx first #define yy second #define all(a) (a).begin(), (a).end() #define pb push_back #define ll long long #define pii pair<int,int> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less) mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int n; int niz[200005]; vector<int> graf[200005]; int dp[200005]; bool bio[200005]; int cale[200005]; int solve(int x, int y){ //if(bio[x])return dp[x]; //bio[x] = 1; cale[x] = y; int tmp = 0; for(auto c:graf[x]){ if(c == y)continue; tmp += solve(c, x); } dp[x] = tmp - niz[x]; dp[x] = max(dp[x], niz[x]); return dp[x]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; ff(i,1,n - 1){ int a,b; cin >> a >> b; graf[a].pb(b); graf[b].pb(a); } string s; cin >> s; ff(i,0,n - 1)niz[i + 1] = (s[i] - '0'); int ans = solve(1, -1); ff(i,1,n){ ans = max(ans, dp[i]); for(auto c:graf[i]){ if(c == cale[i])continue; ans = max(ans, dp[c] + niz[i]); } } cout << ans << "\n"; return 0; }

Compilation message (stderr)

power.cpp: In function 'int main()':
power.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
power.cpp:51:5: note: in expansion of macro 'ff'
   51 |     ff(i,1,n - 1){
      |     ^~
power.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
power.cpp:60:5: note: in expansion of macro 'ff'
   60 |     ff(i,0,n - 1)niz[i + 1] = (s[i] - '0');
      |     ^~
power.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
power.cpp:63:5: note: in expansion of macro 'ff'
   63 |     ff(i,1,n){
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...