Submission #585564

# Submission time Handle Problem Language Result Execution time Memory
585564 2022-06-29T05:11:25 Z amunduzbaev Chase (CEOI17_chase) C++17
0 / 100
46 ms 13404 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef int64_t ll;
#define int ll

const int N = 1e5 + 5;
vector<int> edges[N];
int a[N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, v; cin>>n>>v;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<n;i++){
		int a, b; cin>>a>>b;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	int res = 0;
	for(int i=1;i<=n;i++){
		int d[n + 1] {}, pref[n + 1] {};
		
		function<void(int, int)> dfs = [&](int u, int p){
			for(auto x : edges[u]){
				if(x == p) continue;
				pref[u] += a[x];
			}
			for(auto x : edges[u]){
				if(x == p) continue;
				pref[x] = pref[u];
				d[x] = d[u] + 1;
				dfs(x, u);
			}
		};
		
		pref[i] = a[i];
		dfs(i, i);
		for(int j=1;j<=n;j++){
			if(d[j] < v){
				res = max(res, pref[j] - a[i]);
			}
		}
		
		if(n > 1000) break;
	}
	
	cout<<res<<"\n";
}

/*

12 2
2 3 3 8 1 5 6 7 8 3 5 4
2 1
2 7
3 4
4 7
7 6
5 6
6 8
6 9
7 10
10 11
10 12

*/

# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 13404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 2 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -