# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1069994 | YassineBenYounes | Petrol stations (CEOI24_stations) | C++17 | 3589 ms | 11916 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.
#include <bits/stdc++.h>
using namespace std;
void init(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
typedef long long ll;
#define vi vector<int>
#define pii pair<int, int >
#define vii vector<pii>
#define ff first
#define ss second
#define pb push_back
const int mx = 7e4+5;
#define int ll
vii graph[mx];
int cnt[mx], sz[mx];
int n, k;
int st;
void pre(int node, int p){
sz[node] = 1;
for(pii adj : graph[node]){
if(adj.ff == p)continue;
pre(adj.ff, node);
sz[node] += sz[adj.ff];
}
}
void dfs(int node, int p, int left){
for(pii adj : graph[node]){
if(adj.ff == p)continue;
int nw = left - adj.ss;
if(nw < 0){
cnt[node]+=sz[adj.ff];
dfs(adj.ff, node, k - adj.ss);
}
else{
dfs(adj.ff, node, nw);
}
}
}
int32_t main(){
cin >> n >> k;
for(int i = 1; i < n;i++){
int a, b, c;cin >> a >> b >> c;
graph[a].pb({b, c});
graph[b].pb({a, c});
}
for(int i = 0; i < n;i++){
pre(i, i);
dfs(i, i, k);
}
for(int i = 0; i < n;i++){
cout << cnt[i] << endl;
}
}
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... |