Submission #74361

#TimeUsernameProblemLanguageResultExecution timeMemory
74361rKrPaNPaprike (COI18_paprike)C++98
24 / 100
213 ms53948 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int n,k; int ljut[100010]; vector <int> v[1000010]; int broj = 0; /// DFS int dfs(int x, int par){ vector <int> vec; int summ= 0; if (par != -1 && (int)v[x].size() == 1){ return ljut[x]; } for (int i = 0; i < (int)v[x].size(); i++){ if (v[x][i] != par){ vec.push_back(dfs(v[x][i],x)); summ+= vec[(int)vec.size()-1]; } } sort(vec.begin(),vec.end()); summ+= ljut[x]; while(summ > k){ summ -= vec[(int)vec.size()-1]; vec.pop_back(); broj++; } return summ; } /// MAIN int main (){ cin >> n >> k; for (int i = 1; i <= n; i++){ cin >> ljut[i]; } for (int j = 2; j <= n; j++){ int a,b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } int var = dfs(1,-1); cout << broj << "\n"; return 0; }

Compilation message (stderr)

paprike.cpp: In function 'int main()':
paprike.cpp:58:9: warning: unused variable 'var' [-Wunused-variable]
     int var = dfs(1,-1);
         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...