Submission #889486

#TimeUsernameProblemLanguageResultExecution timeMemory
889486Mr_PhPower Plant (JOI20_power)C++17
100 / 100
96 ms29584 KiB
///Never gonna give you up. #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; typedef long long int lli; typedef unsigned long long ull; using namespace std; using namespace __gnu_pbds; template<class x> using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>; const ll mod=(ll)1e9+7; const ll mod1=998244353; ///the defines :) //#define endl '\n' #define vi vector<int> #define vll vector<ll> #define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i]; #define all(arr) arr.begin(),arr.end() #define allr(arr) arr.rbegin(),arr.rend() #define sz size() #define int long long vector<vector<int>>adj; string s; int n; int dp[200001]; int ans1=0; int ans(int node,int p) { //cout<<node<<" "<<p<<endl; if(dp[node]!=-1)return dp[node]; int e=0,e1=0; for(auto i:adj[node]) {// //cout<<i<<endl; if(i==p)continue; int x=ans(i,node); if(s[node-1]=='1') ans1=max(ans1,x+1); e1+=x; } if(s[node-1]=='1')e1=max(e1-1,1ll); return dp[node]=e1; } void preprocess() {} void solve() { memset(dp,-1,sizeof dp); cin>>n; adj.resize(n+1); for(int i=0;i<n-1;i++) { int a,b; cin>>a>>b; adj[a].push_back(b); adj[b].push_back(a); } cin>>s; cout<<max(ans(1,-1),ans1)<<endl; } signed main() { // freopen("div7.in","r",stdin); //freopen("div7.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); preprocess(); //bla(); int t=1; //cin>>t; while(t--) solve(); }

Compilation message (stderr)

power.cpp: In function 'long long int ans(long long int, long long int)':
power.cpp:32:9: warning: unused variable 'e' [-Wunused-variable]
   32 |     int e=0,e1=0;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...