Submission #502221

# Submission time Handle Problem Language Result Execution time Memory
502221 2022-01-05T14:32:32 Z amunduzbaev Power Plant (JOI20_power) C++14
0 / 100
1 ms 364 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
//~ #define int long long

const int N = 2e3 + 5;
vector<int> edges[N];
int a[N], dp[N];

void dfs(int u, int p = -1){
	for(auto x : edges[u]){
		if(x == p) continue;
		dfs(x, u);
		dp[u] += dp[x];
	} 
	
	dp[u] = max(dp[u] - a[u], 0);
	if(a[u]) dp[u] = max(dp[u], 1);
}

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);

	int n; cin>>n;
	for(int i=1;i<n;i++){
		int a, b; cin>>a>>b;
		edges[a].push_back(b);
		edges[b].push_back(a);
	} for(int i=1;i<=n;i++){
		char c; cin>>c;
		a[i] = c - '0';
	}
	
	int res = 0;
	for(int i=1;i<=n;i++){
		memset(dp, 0, sizeof dp);
		dfs(i);
		//~ cout<<dp[i]<<"\n";
		res = max(res, dp[i]);
	} cout<<res<<"\n";
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Incorrect 0 ms 332 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Incorrect 0 ms 332 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Incorrect 0 ms 332 KB Output isn't correct
9 Halted 0 ms 0 KB -