제출 #1045797

#제출 시각아이디문제언어결과실행 시간메모리
1045797alex_2008Petrol stations (CEOI24_stations)C++14
18 / 100
3556 ms10380 KiB
#include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <map> #include <queue> #include <stack> #include <set> typedef long long ll; using namespace std; const int N = 70070; int cnt[N]; int subtree[N]; vector <vector<pair<int, int>>> G; int n, k; void dfs_0(int v, int p) { subtree[v] = 1; for (auto it : G[v]) { if (it.first == p) continue; dfs_0(it.first, v); subtree[v] += subtree[it.first]; } } void dfs(int v, int p, int depth) { for (auto it : G[v]) { if (it.first == p) continue; int c = depth + it.second; if (c <= k) dfs(it.first, v, c); else { cnt[v] += subtree[it.first]; dfs(it.first, v, it.second); } } } int main() { cin >> n >> k; G.resize(n + 1); for (int i = 1; i < n; i++) { int a, b, c; cin >> a >> b >> c; a++; b++; G[a].push_back({ b, c }); G[b].push_back({ a, c }); } for (int i = 1; i <= n; i++) { dfs_0(i, i); dfs(i, i, 0); } for (int i = 1; i <= n; i++) { cout << cnt[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...