Submission #372860

#TimeUsernameProblemLanguageResultExecution timeMemory
372860sam571128Janjetina (COCI21_janjetina)C++14
15 / 110
1542 ms9836 KiB
#include <bits/stdc++.h> #define int long long #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; const int N = 1e5+5; vector<pair<int,int>> adj[N]; int ans = 0; int dis[N], mx[N]; void dfs(int u, int par){ for(auto [v,w] : adj[u]){ if(v==par) continue; dis[v] = dis[u]+1; mx[v] = max(mx[u],w); dfs(v,u); } } signed main(){ fastio int n,k; cin >> n >> k; for(int i = 0;i < n-1;i++){ int u,v,w; cin >> u >> v >> w; adj[u].push_back({v,w}); adj[v].push_back({u,w}); } for(int i = 1;i <= n;i++){ fill(mx,mx+n+1,0); dis[i] = 0; dfs(i,-1); for(int j = 1;j <= n;j++){ if(mx[j]-dis[j] >= k&&i!=j){ ans++; } } } cout << ans << "\n"; }

Compilation message (stderr)

Main.cpp: In function 'void dfs(long long int, long long int)':
Main.cpp:14:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   14 |  for(auto [v,w] : adj[u]){
      |           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...