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;
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |