Submission #1099084

#TimeUsernameProblemLanguageResultExecution timeMemory
1099084vjudge1Janjetina (COCI21_janjetina)C++17
15 / 110
11 ms608 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...