Submission #1100329

#TimeUsernameProblemLanguageResultExecution timeMemory
1100329vjudge1Janjetina (COCI21_janjetina)C++17
15 / 110
14 ms7508 KiB
#include<bits/stdc++.h> using namespace std; int n,k,ans,dp[200005],o; vector<pair<int,int>>v[200005]; void dfs(int x,int l,int w) { if(dp[x])return; dp[x]=1; if(o!=x&&w-l>=k) { //cout<<w-l<<' '<<o<<' '<<x<<'\n'; ans++; } for(auto [i,vl]:v[x]) { int mx=max(w,vl); dfs(i,l+1,mx); } dp[x]=0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>k; for(int x=0;x<n-1;x++) { int l,r,vl; cin>>l>>r>>vl; v[l].push_back({r,vl}); v[r].push_back({l,vl}); } //cout<<'\n'; if(n<=1000) { for(int x=1;x<=n;x++) { o=x; dp[x]=1; for(auto [i,vl]:v[x]) { dfs(i,1,vl); } dp[x]=0; } cout<<ans; } else { cout<<0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...