제출 #373031

#제출 시각아이디문제언어결과실행 시간메모리
373031PixelCatPower Plant (JOI20_power)C++14
0 / 100
5 ms5356 KiB
/* /^--^\ \____/ / \ _____ _ __ __ ____ _ ____ ____ _____ | || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_ _| \__ __/ |_| |_|/_/\_\|____||____|\____)/__/\__\ |_| |^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^| | | |\ \| | | | | | | | | | | | | | | | | | | | | | | | | #####/ /################################################# | | |\/ | | | | | | | | | | | | | | | | | | | | | | | | | |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|*/ //#pragma GCC optimize("O4,unroll-loops,no-stack-protector") #include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; using pii=pair<ll,ll>; #define int ll #define double long double #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 F first #define S second #define L(id) (id*2+1) #define R(id) (id*2+2) #define LO(x) (x&(-x)) #define eb emplace_back #define all(x) x.begin(),x.end() #define sz(x) ((int)x.size()) #define mkp make_pair #define MOD (ll)(1000000007) #define INF (ll)(1e15) #define EPS (1e-9) #ifdef LOCALMEOW #define debug(...) do{\ cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ <<\ " : ("#__VA_ARGS__ << ") = ";\ _OUT(__VA_ARGS__);\ }while(0) template<typename T> void _OUT(T x) { cerr << x << "\n"; } template<typename T,typename...I> void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); } #else #define debug(...) #endif inline void IOS(){ ios::sync_with_stdio(false); cin.tie(0); } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int gcd(int a,int b) { return b==0?a:gcd(b,a%b); } int lcm(int a,int b) { return a/gcd(a,b)*b; } int fpow(int b,int p){ int ans=1,now=b; while(p){ if(p&1) ans=ans*now%MOD; p/=2; now=now*now%MOD; } return ans; } void minify(int &a,int b) { if(b<a) a=b; } void maxify(int &a,int b) { if(b>a) a=b; } list<int> adj[200020]; string power; int one[200020]; int ans[200020]; void go(int n,int p){ for(auto &i:adj[n]) if(i!=p) go(i,n); if(power[n-1]=='0'){ one[n]=ans[n]=0; for(auto &i:adj[n]){ if(i!=p){ one[n]+=one[i]; ans[n]=max(ans[n],ans[i]); } } ans[n]=max(ans[n],one[n]); }else{ ans[n]=1; one[n]=-1; for(auto &i:adj[n]){ if(i!=p){ one[n]+=one[i]; ans[n]=max(ans[n],max(1+one[i],ans[i])); } } one[n]=max(one[n],1ll); } } int32_t main(){ IOS(); //code... int n; cin>>n; int a,b; For(i,1,n-1){ cin>>a>>b; adj[a].eb(b); adj[b].eb(a); } cin>>power; go(1,1); a=0; For(i,1,n) a=max(ans[i],a); cout<<a<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...