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>
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |