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;
const int mxN = 1e3 + 3;
vector<pair<int, int>> G[mxN];
int depth[mxN][mxN], path_mx[mxN][mxN];
void dfs(int node, int par, int root){
for(pair<int, int> &v : G[node]){
if(v.first != par){
depth[root][v.first] = depth[root][node] + 1;
path_mx[root][v.first] = max(path_mx[root][node], v.second);
dfs(v.first, node, root);
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
for(int i = 1;i < n;++i){
int u, v, w;
cin >> u >> v >> w;
G[u].push_back({v, w});
G[v].push_back({u, w});
}
for(int i = 1;i <= n;++i){
dfs(i, i, i);
}
long long res = 0;
for(int i = 1;i <= n;++i){
for(int j = 1;j <= n;++j){
if(i != j && path_mx[i][j] - depth[i][j] >= k){
res++;
}
}
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |