Submission #201803

#TimeUsernameProblemLanguageResultExecution timeMemory
201803anonymousPaprike (COI18_paprike)C++14
51 / 100
95 ms15736 KiB
#include<iostream> #include<vector> #include<algorithm> #define MAXN 100005 using namespace std; int N,K,wt[MAXN]; int ui,vi,ans; vector <int> adj[MAXN]; int dfs(int u, int prev) { vector <int> Val; for (auto v: adj[u]) { if (v != prev) {Val.push_back(dfs(v,u));} } sort(Val.begin(), Val.end()); int S=wt[u], r=0; for (auto w: Val) { if (S+w<=K) {S+=w, r++;} else {break;} } ans+=Val.size() - r; Val.clear(); return(S); } int main() { //freopen("paprikein.txt","r",stdin); scanf("%d %d",&N,&K); for (int i=1; i<=N; i++) { scanf("%d",&wt[i]); } for (int i=1; i<N; i++) { scanf("%d %d",&ui,&vi); adj[ui].push_back(vi); adj[vi].push_back(ui); } dfs(1,0); printf("%d\n", ans); }

Compilation message (stderr)

paprike.cpp: In function 'int main()':
paprike.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&N,&K);
     ~~~~~^~~~~~~~~~~~~~~
paprike.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&wt[i]);
         ~~~~~^~~~~~~~~~~~~
paprike.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&ui,&vi);
         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...