이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |