Submission #1036522

#TimeUsernameProblemLanguageResultExecution timeMemory
1036522model_codePetrol stations (CEOI24_stations)C++17
18 / 100
3581 ms30876 KiB
// Author: Jiří Kalvoda #include<bits/stdc++.h> using namespace std; using ll = long long; int n; ll k; struct Node{ vector<pair<Node*, ll>> e; ll counts=0; int id; int go(ll current_power, Node *from) { int subtree_size = 1; for(auto &[nd, l] : e) if(nd != from) { ll r_power = current_power - l; if(r_power < 0) { int r_subtree_size = nd->go(k-l, this); counts += r_subtree_size; subtree_size += r_subtree_size; } else subtree_size += nd->go(r_power, this); } return subtree_size; } } *nds; int main(int argc, char ** argv) { scanf("%d%lld", &n, &k); nds = new Node[n]; for (int i=0; i<n; i++) nds[i].id = i; for (int i=0; i<n-1; i++) { int a,b; ll l; scanf("%d%d%lld", &a, &b, &l); nds[a].e.push_back({nds+b, l}); nds[b].e.push_back({nds+a, l}); } for (int i=0; i<n; i++) nds[i].go(k, NULL); for (int i=0; i<n; i++) printf("%lld\n", nds[i].counts); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main(int, char**)':
Main.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  scanf("%d%lld", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   scanf("%d%d%lld", &a, &b, &l);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...