이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define in insert
#define F first
#define S second
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define endl '\n'
#define pii pair<ll,ll>
using namespace std;
const ll INF =1e18, mod = 1e9 + 7, N = 1e5 + 5;
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;
}
vector<ll>g[N];
ll used[N];
ll n,k;
ll a[N];
ll cnt = 0;
void dfs(ll s, ll u,ll &sum){
sum = a[s];
vector<ll>v;
for(auto i : g[s]){
if(i != u){
ll r = 0;
dfs(i,s,r);
v.pb(r);
}
}
sort(all(v));
for(int i = 0; i < v.size(); i++){
if(v[i] + sum > k){
cnt++;
}
else{
sum += v[i];
}
}
if(sum > k){
cnt++;
}
}
void solve(){
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
ll x,y;
for(int i = 0; i < n - 1; i++){
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
ll sum;
dfs(1,-1, sum);
cout << cnt << endl;
}
int main(){
fast;
ll t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
paprike.cpp: In function 'void dfs(long long int, long long int, long long int&)':
paprike.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |