제출 #1117981

#제출 시각아이디문제언어결과실행 시간메모리
1117981vjudge1Paprike (COI18_paprike)C++17
100 / 100
104 ms84080 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define run  ios_base::sync_with_stdio(false);cin.tie(0);
 
#define ll long long
#define pll pair<ll, ll>
#define ull unsigned ll
#define ld double
#define endl "\n"
#define pb push_back
#define fi first
#define se second
 
#define pi acos(-1)
#define N 3000007
#define minimum -9223372036854775807
#define maximum -minimum
#define mod 1000000007
 
using namespace std;
using namespace __gnu_pbds;
template <class t>
using ordered_set=tree<t, null_type,less_equal<t>, rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll gcd(ll a, ll b)
{
	if(b==0)
		return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
	return a/gcd(a, b)*b;
}

bool isprime(ll n)
{
	if(n==1)
		return 0;
	for(ll i=2; i*i<=n; i++)
	{
		if(n%i==0)
			return 0;
	}
	return 1;
}

ll binpow(ll a, ll b)
{
    a%=mod;
    ll res=1;
    while(b>0)
	{
        if(b%2==1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}

ll n, m, res;
ll a[N];
vector<ll>v[N];

void dfs(ll node, ll par)
{
	vector<ll>vv;
	for(ll i:v[node])
	{
		if(i==par)
			continue;
		dfs(i, node);
		vv.pb(a[i]);
	}
	sort(vv.begin(), vv.end());
	for(ll i=0; i<vv.size(); i++)
	{
		if(a[node]+vv[i]<=m)
		{
			a[node]+=vv[i];
		}
		else
		{
			res++;
		}
	}
}

int main()
{
    run;
    cin>>n>>m;
    for(ll i=1; i<=n; i++)
    {
    	cin>>a[i];
	}
	for(ll i=1; i<n; i++)
	{
		ll x, y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	res=0;
	dfs(1, 1);
	cout<<res<<endl;
}
// By Xanlar

컴파일 시 표준 에러 (stderr) 메시지

paprike.cpp: In function 'void dfs(long long int, long long int)':
paprike.cpp:81:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |  for(ll i=0; i<vv.size(); i++)
      |              ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...