Submission #626430

#TimeUsernameProblemLanguageResultExecution timeMemory
626430codr0Power Plant (JOI20_power)C++14
6 / 100
127 ms468 KiB
// Code by Parsa Eslami #include <bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORR(i,a,b) for(int i=a;i>=b;i--) #define maxm(a,b) a=max(a,b) #define minm(a,b) a=min(a,b) #define all(x) x.begin(),x.end() #define SZ(x) ((int)x.size()) #define bit(i,j) ((j>>i)&1) #define pb push_back #define lc 2id #define rc 2id+1 #define dmid int mid=(r+l)/2 #define err(x) cerr<#x<<" : "<<x<<'\n' using namespace std; const int N=16+1; int get(){ int x; cin>>x; return x; } vector<int> adj[N]; int sz[N]; bool gen[N]; bool on[N]; int n; void dfs(int v,int p){ sz[v]=on[v]; for(int u:adj[v]) if(u!=p) dfs(u,v),sz[v]+=sz[u]; } int check(){ FOR(i,1,n) if(!gen[i]&&on[i]) return 0; int rt=0; FOR(i,1,n){ dfs(i,i); int y=0; for(int u:adj[i]) y+=(sz[u]>0); if(on[i]&&y>1) return 0; if(gen[i]&&y>1) rt--; if(on[i]) rt++; } return rt; } int32_t main(){ iostream::sync_with_stdio(0); cin.tie(0); n=get(); FOR(i,1,n-1){ int u=get(),v=get(); adj[u].pb(v); adj[v].pb(u); } string s; cin>>s; FOR(i,0,n-1) gen[i+1]=s[i]-'0'; int ot=0; FOR(msk,0,(1<<n)-1){ FOR(j,0,n-1) on[j+1]=bit(j,msk); maxm(ot,check()); } cout<<ot<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...