Submission #1053205

#TimeUsernameProblemLanguageResultExecution timeMemory
1053205elazarkorenPetrol stations (CEOI24_stations)C++17
18 / 100
3581 ms11608 KiB
#include <bits/stdc++.h> #define x first #define y second #define all(v) v.begin(), v.end() #define chkmin(a, b) a = min(a, b) #define chkmax(a, b) a = max(a, b) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vii; const int MAX_N = 1e5 + 5; ll ans[MAX_N]; vii tree[MAX_N]; ll sz[MAX_N]; int n, k; int DfsSz(int node, int parent) { sz[node] = 1; for (auto [neighbor, w] : tree[node]) { if (neighbor != parent) { sz[node] += DfsSz(neighbor, node); } } return sz[node]; } void Solve(int node, int parent, int d) { for (auto [neighbor, w] : tree[node]) { if (neighbor == parent) continue; if (d < w) { ans[node] += sz[neighbor]; Solve(neighbor, node, k - w); } else Solve(neighbor, node, d - w); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 0; i < n - 1; i++) { int u, v, l; cin >> u >> v >> l; tree[u].push_back({v, l}); tree[v].push_back({u, l}); } for (int i = 0; i < n; i++) { DfsSz(i, -1); Solve(i, -1, k); } for (int i = 0; i < n; i++) cout << ans[i] << '\n'; }
#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...