#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
#define i2 array<int,2>
using namespace std;
typedef long long ll;
const int MX = int(1e7) + 10;
const int oo = 2e9;
const int N = 2010;
vector<i2> g[N];
int n, k, ans;
void dfs(int v, int p, int mx, int len){
if (mx - len >= k)
ans++;
for (i2 u : g[v]){
if (u[0] == p) continue;
dfs(u[0], v, max(mx, u[1]), len + 1);
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> k;
// assert(n <= 100);
for (int i = 1; i < n; i++){
int x, y, w; cin >> x >> y >> w;
x--; y--;
g[x].PB({y, w});
g[y].PB({x, w});
}
for (int i = 0; i < n; i++)
dfs(i, -1, 0, 0);
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
492 KB |
Output is correct |
5 |
Correct |
10 ms |
492 KB |
Output is correct |
6 |
Correct |
9 ms |
492 KB |
Output is correct |
7 |
Correct |
9 ms |
492 KB |
Output is correct |
8 |
Correct |
9 ms |
492 KB |
Output is correct |
9 |
Correct |
10 ms |
364 KB |
Output is correct |
10 |
Correct |
11 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
364 KB |
Output is correct |
12 |
Correct |
15 ms |
364 KB |
Output is correct |
13 |
Correct |
14 ms |
364 KB |
Output is correct |
14 |
Correct |
16 ms |
364 KB |
Output is correct |
15 |
Correct |
15 ms |
364 KB |
Output is correct |
16 |
Correct |
14 ms |
364 KB |
Output is correct |
17 |
Correct |
15 ms |
364 KB |
Output is correct |
18 |
Correct |
13 ms |
364 KB |
Output is correct |
19 |
Correct |
14 ms |
364 KB |
Output is correct |
20 |
Correct |
14 ms |
364 KB |
Output is correct |
21 |
Correct |
14 ms |
364 KB |
Output is correct |
22 |
Correct |
13 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
492 KB |
Output is correct |
5 |
Runtime error |
2 ms |
748 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
492 KB |
Output is correct |
5 |
Correct |
10 ms |
492 KB |
Output is correct |
6 |
Correct |
9 ms |
492 KB |
Output is correct |
7 |
Correct |
9 ms |
492 KB |
Output is correct |
8 |
Correct |
9 ms |
492 KB |
Output is correct |
9 |
Correct |
10 ms |
364 KB |
Output is correct |
10 |
Correct |
11 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
364 KB |
Output is correct |
12 |
Correct |
15 ms |
364 KB |
Output is correct |
13 |
Correct |
14 ms |
364 KB |
Output is correct |
14 |
Correct |
16 ms |
364 KB |
Output is correct |
15 |
Correct |
15 ms |
364 KB |
Output is correct |
16 |
Correct |
14 ms |
364 KB |
Output is correct |
17 |
Correct |
15 ms |
364 KB |
Output is correct |
18 |
Correct |
13 ms |
364 KB |
Output is correct |
19 |
Correct |
14 ms |
364 KB |
Output is correct |
20 |
Correct |
14 ms |
364 KB |
Output is correct |
21 |
Correct |
14 ms |
364 KB |
Output is correct |
22 |
Correct |
13 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
9 ms |
492 KB |
Output is correct |
27 |
Runtime error |
2 ms |
748 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |