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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "memory.h"
#define bitcount __builtin_popcountll
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<long long,null_type,less_equal<>,rb_tree_tag,tree_order_statistics_node_update>;
vector<pair<int,int>> adj[1000];
int mx[1000], dep[1000];
void dfs(int u, int p = -1) {
for (auto [v, w] : adj[u]) if (v != p) {
dep[v] = dep[u] + 1;
mx[v] = max(mx[u], w);
dfs(v, u);
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int n,k; cin >> n >> k;
for (int i = 0; i < n-1; i++) {
int u,v,w; cin >> u >> v >> w;
u--, v--;
adj[u].emplace_back(v, w);
adj[v].emplace_back(u, w);
}
long long ans = 0;
for (int i = 0; i < n; i++) {
dep[i] = mx[i] = 0;
dfs(i);
for (int j = 0; j < n; j++) if (mx[j] - dep[j] >= k) {
ans++;
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |