# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1036522 | model_code | Petrol stations (CEOI24_stations) | C++17 | 3581 ms | 30876 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 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)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |