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>
using namespace std;
long long n, k, cnt = 0, sum, height;
vector<pair<int, int>> vec[100001];
bool check = 0;
void dfs(int x, int p, int len, int h)
{
if(len - h >= k) ++cnt;
for(pair<int, int> c : vec[x]) if(c.first != p) dfs(c.first, x, max(len, c.second), h + 1);
}
int main()
{
ios::sync_with_stdio (false);
cin.tie (0); cout.tie (0);
cin >> n >> k;
for(int i = 1; i < n; ++i)
{
long long x, y, z;
cin >> x >> y >> z;
vec[x].push_back({y, z});
vec[y].push_back({x, z});
}
for(int i = 1; i <= n; ++i)
{
dfs(i, 0, 0, 0);
}
cout << cnt;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |