Submission #417179

#TimeUsernameProblemLanguageResultExecution timeMemory
417179Knps4422Power Plant (JOI20_power)C++14
47 / 100
1585 ms36020 KiB
//#pragma optimization_level 3 //#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include<bits/stdc++.h> /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset; */ #define fr first #define sc second #define vec vector #define pb push_back #define pii pair<int, int> #define forn(x,y) for(int x = 1 ; x <= (int)y ; ++x) #define all(x) (x).begin(),(x).end() #define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0); using namespace std; typedef long long ll; typedef unsigned int uint; typedef pair<ll,ll> pll; typedef complex<int> point; const int nmax = 200005; const ll linf = 1e18; const ll mod = 998244353; const int inf = 1e9+10; const int sq = 5000; int n; char asd[nmax]; int viz[nmax]; vec < int > g[nmax] , ng[nmax]; pii edges[2*nmax]; int done[2*nmax]; int dp[2*nmax]; int compute_dp(int ed){ int nod1 = edges[ed].fr , nod2 = edges[ed].sc; if(done[ed] == 1){ //cout << "dp: " << nod1 << ' '<< nod2 << ' '<< dp[{nod1,nod2}].fr << '\n'; return dp[ed]; } int rs = -(asd[nod2] == '1') , rs2 = (asd[nod2] == '1'); for(int i : g[nod2]){ if(edges[i].sc != nod1){ rs += compute_dp(i); } } dp[ed] = max(rs,rs2); done[ed] = 1; //cout << "dp: " << nod1 << ' '<< nod2 << ' '<< max(rs,rs2) << '\n'; return dp[ed]; } int main(){ cin >> n; for(int i = 1; i < n; i++){ int a, b; cin >> a >> b; g[a].pb(i); g[b].pb(n+i); edges[i] = {a,b}; edges[i+n] = {b,a}; } int cnt = 0; for(int i = 1; i <= n; i++){ cin >> asd[i]; cnt += (asd[i] == '1'); } int rez; if(cnt >= 2){ rez = 2; }else{ rez = 1; } for(int i = 1; i <= n; i++){ int rs; //cout << "COMPUTE " << i << '\n'; if(asd[i] == '1')rs = -1; else rs = 0; //cout << rs << '\n'; for(int ed : g[i]){ int j = edges[ed].sc; rs += compute_dp(ed); } //cout << i << ' ' << rs << '\n'; rez = max(rez,rs); } cout << rez << '\n'; }

Compilation message (stderr)

power.cpp: In function 'int main()':
power.cpp:86:8: warning: unused variable 'j' [-Wunused-variable]
   86 |    int j = edges[ed].sc;
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...