답안 #572115

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572115 2022-06-03T16:49:42 Z MODDI Paprike (COI18_paprike) C++14
0 / 100
784 ms 1048576 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
using namespace std;
int n, q;
vi G[100010], sum, size;
ll rez = 0;
void dfs(int at, int parent){
	vl deca;
	ll gol = G[at].size() - 1;
	if(at == 0)
		gol++;
		
	for(auto it : G[at]){
		if(at == parent)
			continue;
			
		dfs(it, at);
		deca.pb(size[it]);
	}
	sort(deca.begin(), deca.end());
	for(auto it : deca){
		if(size[at] + it <= q){
			size[at] += it;
			gol--;
		}
		else{
			rez += gol;
			return;
		}
	}
}
int main(){
	cin>>n>>q;
	sum.resize(n);
	size.resize(n);
	ll mby = 0;
	for(int i = 0; i < n; i++){
		cin>>sum[i];
		mby += sum[i];
		size[i] = sum[i];
	}
	for(int i = 0; i < n - 1; i++){
		int a, b;
		cin>>a>>b;
		a--; b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	if(mby <= q)
	{
		cout<<0<<endl;
		return 0;
	}
	dfs(0, -1);
	cout<<rez<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 784 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 611 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 784 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 784 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -