Submission #412440

# Submission time Handle Problem Language Result Execution time Memory
412440 2021-05-26T22:05:55 Z CSQ31 Power Plant (JOI20_power) C++14
0 / 100
5 ms 6476 KB
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e8)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MAXN = 2e5+5;
ll ans = 0;
vector<ll>dp(MAXN);
vii adj(MAXN);
string s;
void dfs(int v,int u){
	dp[v] = (s[v]=='1');
	ll mx = 0,sum =0;
	for(int x:adj[v]){
		if(x == u)continue;
		dfs(x,v);
		mx = max(mx,dp[x]);
		sum+=dp[x];
	}
	if(s[v] == '1')ans = max(ans,mx+1);
	dp[v] = max(dp[v],sum-dp[v]);
	ans = max(ans,dp[v]);
}
int main()
{
	owo
	int n;
	cin>>n;
	for(int i=1;i<n;i++){
		int v,u;
		cin>>v>>u;
		v--;
		u--;
		adj[v].pb(u);
		adj[u].pb(v);
	}
	cin>>s;
	dfs(1,0);
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 6476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 6476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 6476 KB Output isn't correct
2 Halted 0 ms 0 KB -