#include<bits/stdc++.h>
using namespace std;
long long n, k, cnt = 0, sum, height;
vector<pair<int, int>> vec[1001];
bool check = 0;
void dfs(int x, int y, int p, int len, int h)
{
if(x == y)
{
sum = len;
height = h;
check = true;
return;
}
for(pair<int, int> c : vec[x])
{
if(c.first != p) dfs(c.first, y, x, max(len, c.second), h + 1);
if(check) return;
}
}
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)
{
for(int j = i + 1; j <= n; ++j)
{
check = height = sum = 0;
dfs(i, j, 0, 0, 0);
if(sum - height >= k)
{
++cnt;
}
}
}
cout << cnt * 2;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:40:19: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
40 | check = height = sum = 0;
| ~~~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Execution timed out |
1587 ms |
340 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Execution timed out |
1572 ms |
340 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Execution timed out |
1587 ms |
340 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |