#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 time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
8 ms |
348 KB |
Output is correct |
4 |
Correct |
15 ms |
348 KB |
Output is correct |
5 |
Correct |
12 ms |
520 KB |
Output is correct |
6 |
Correct |
21 ms |
344 KB |
Output is correct |
7 |
Correct |
18 ms |
572 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
12 ms |
348 KB |
Output is correct |
10 |
Correct |
10 ms |
348 KB |
Output is correct |
11 |
Correct |
16 ms |
508 KB |
Output is correct |
12 |
Correct |
12 ms |
348 KB |
Output is correct |
13 |
Correct |
12 ms |
348 KB |
Output is correct |
14 |
Correct |
7 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
3520 ms |
10380 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Execution timed out |
3520 ms |
10380 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
3556 ms |
4692 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
3556 ms |
4692 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
8 ms |
348 KB |
Output is correct |
4 |
Correct |
15 ms |
348 KB |
Output is correct |
5 |
Correct |
12 ms |
520 KB |
Output is correct |
6 |
Correct |
21 ms |
344 KB |
Output is correct |
7 |
Correct |
18 ms |
572 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
12 ms |
348 KB |
Output is correct |
10 |
Correct |
10 ms |
348 KB |
Output is correct |
11 |
Correct |
16 ms |
508 KB |
Output is correct |
12 |
Correct |
12 ms |
348 KB |
Output is correct |
13 |
Correct |
12 ms |
348 KB |
Output is correct |
14 |
Correct |
7 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Execution timed out |
3520 ms |
10380 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |