제출 #465437

#제출 시각아이디문제언어결과실행 시간메모리
465437osmanallazovPaprike (COI18_paprike)C++14
0 / 100
122 ms17448 KiB
#include <bits/stdc++.h> using namespace std; long long n,k; long long ans=0; long long val[100005]; long long a[100005]; long long b[100005]; vector<long long>qraf[100005]; int dfs(long long x, long long par){ vector<long long>v; for(long long i=0;i<(long long)(qraf[x]).size();i++){ long long child=qraf[x][i]; if(child==par) continue; v.push_back(dfs(child,x)); } sort(v.begin(),v.end()); long long sum=0; for(long long i=0;i<v.size();i++) sum += v[i]; for(long long i=v.size()-1;i>=0;i--){ if(sum>k){ sum-=v[i]; ans++; } else{break;} } return sum; } int main (){ cin>>n>>k; for(int i=0; i<n; i++){ cin>>val[i]; } for(int i=0; i<n-1; i++){ cin>>a[i]>>b[i]; qraf[a[i]].push_back(b[i]); qraf[b[i]].push_back(a[i]); } dfs(1,0); cout<<ans; }

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

paprike.cpp: In function 'int dfs(long long int, long long int)':
paprike.cpp:20:24: 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]
   20 |     for(long long i=0;i<v.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...