Submission #1113850

# Submission time Handle Problem Language Result Execution time Memory
1113850 2024-11-17T15:26:46 Z Dan4Life Power Plant (JOI20_power) C++17
0 / 100
3 ms 6480 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
#define int long long
const int N = (int)2e5+2;
int n;
string gen;
vector<int> adj[N];
int dp[N],ans;

void dfs(int s, int p){
	vector<int> v; v.clear();
	for(auto u : adj[s]){
		if(u==p) continue;
		dfs(u,s); v.pb(dp[u]);
	}
	int sum = 0, best = 0;
	for(auto u : v) sum+=u,best=max(best,u);
	if(gen[s]=='0') dp[s]=sum,ans=max(ans,dp[s]);
	else dp[s]=max(1ll,sum-1),ans=max(ans,best+1);
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n; fill(dp,dp+n+1,-n*n);
	for(int i = 1; i < n; i++){
		int a, b; cin >> a >> b;
		adj[a].pb(b), adj[b].pb(a);
	}
	cin >> gen; gen='$'+gen; dfs(1,0); 
	cout << *max_element(dp+1,dp+n+1) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6480 KB Output is correct
3 Correct 3 ms 6480 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 3 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Incorrect 3 ms 6480 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6480 KB Output is correct
3 Correct 3 ms 6480 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 3 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Incorrect 3 ms 6480 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6480 KB Output is correct
3 Correct 3 ms 6480 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 3 ms 6480 KB Output is correct
6 Correct 2 ms 6480 KB Output is correct
7 Incorrect 3 ms 6480 KB Output isn't correct
8 Halted 0 ms 0 KB -