Submission #465442

# Submission time Handle Problem Language Result Execution time Memory
465442 2021-08-16T06:41:01 Z fuad27 Paprike (COI18_paprike) C++17
0 / 100
2 ms 3404 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vii vector<pair<int, int>>
#define vi vector<int>
#define vl vector<long long>
#define vll vector<pair<long long, long long>>
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i = a;i<=(b);i++)
#define f first
#define s second
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
#define start int tt;cin>>tt;rep(testcase, 1, tt)
#define print(k) cout<<"Case #"<<testcase<<": "<<k<<"\n";
#define endl "\n"
#define int long long
#define DEBUG(k) cerr<<k<<"\n";
vector<int> w(100010, 0);
int ans = 0, n, k;
vector<int> g[100010];
int s[100010], a[100010];
void dfs(int v,int p)
{
	s[v]=a[v];
	vector <long long> q;
	for(auto x:g[v])
	{
		if(x!=p)
		{
			dfs(x,v);
			s[v]+=s[x];
			q.push_back(s[x]);
		}
	}
	sort(q.begin(),q.end());
	auto it = q.end();
	it--;
	while(s[v]>k)
	{
		s[v]-=*it;
		ans++;
		it--;
	}
}
void solve() {
	cin >> n >> k;
	rep(i, 1, n)cin>>a[i];
	rep(i, 0, n-2) {
		int x, y;
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1, 0);
	cout<<ans<<endl;
}
int32_t main () {
	#ifndef ONLINE_JUDGE
	freopen("stdin", "r", stdin);
	freopen("stdout", "w", stdout);
	freopen("stderr", "w", stderr);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
	return 0;
}

Compilation message

paprike.cpp: In function 'int32_t main()':
paprike.cpp:61:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  freopen("stdin", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
paprike.cpp:62:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |  freopen("stdout", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
paprike.cpp:63:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |  freopen("stderr", "w", stderr);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3404 KB Output isn't correct
2 Halted 0 ms 0 KB -