#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 |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5116 KB |
Output is correct |
4 |
Correct |
10 ms |
5204 KB |
Output is correct |
5 |
Correct |
10 ms |
5204 KB |
Output is correct |
6 |
Correct |
10 ms |
5172 KB |
Output is correct |
7 |
Correct |
11 ms |
5204 KB |
Output is correct |
8 |
Correct |
14 ms |
5204 KB |
Output is correct |
9 |
Correct |
9 ms |
5204 KB |
Output is correct |
10 |
Correct |
10 ms |
5204 KB |
Output is correct |
11 |
Correct |
9 ms |
5204 KB |
Output is correct |
12 |
Correct |
10 ms |
5204 KB |
Output is correct |
13 |
Correct |
10 ms |
5204 KB |
Output is correct |
14 |
Correct |
9 ms |
5204 KB |
Output is correct |
15 |
Correct |
9 ms |
5204 KB |
Output is correct |
16 |
Correct |
9 ms |
5204 KB |
Output is correct |
17 |
Correct |
14 ms |
5204 KB |
Output is correct |
18 |
Correct |
10 ms |
5368 KB |
Output is correct |
19 |
Correct |
9 ms |
5368 KB |
Output is correct |
20 |
Correct |
9 ms |
5204 KB |
Output is correct |
21 |
Correct |
9 ms |
5204 KB |
Output is correct |
22 |
Correct |
10 ms |
5204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
5036 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
10 ms |
5204 KB |
Output is correct |
5 |
Correct |
4 ms |
5460 KB |
Output is correct |
6 |
Incorrect |
12 ms |
7508 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
5116 KB |
Output is correct |
4 |
Correct |
10 ms |
5204 KB |
Output is correct |
5 |
Correct |
10 ms |
5204 KB |
Output is correct |
6 |
Correct |
10 ms |
5172 KB |
Output is correct |
7 |
Correct |
11 ms |
5204 KB |
Output is correct |
8 |
Correct |
14 ms |
5204 KB |
Output is correct |
9 |
Correct |
9 ms |
5204 KB |
Output is correct |
10 |
Correct |
10 ms |
5204 KB |
Output is correct |
11 |
Correct |
9 ms |
5204 KB |
Output is correct |
12 |
Correct |
10 ms |
5204 KB |
Output is correct |
13 |
Correct |
10 ms |
5204 KB |
Output is correct |
14 |
Correct |
9 ms |
5204 KB |
Output is correct |
15 |
Correct |
9 ms |
5204 KB |
Output is correct |
16 |
Correct |
9 ms |
5204 KB |
Output is correct |
17 |
Correct |
14 ms |
5204 KB |
Output is correct |
18 |
Correct |
10 ms |
5368 KB |
Output is correct |
19 |
Correct |
9 ms |
5368 KB |
Output is correct |
20 |
Correct |
9 ms |
5204 KB |
Output is correct |
21 |
Correct |
9 ms |
5204 KB |
Output is correct |
22 |
Correct |
10 ms |
5204 KB |
Output is correct |
23 |
Correct |
2 ms |
4948 KB |
Output is correct |
24 |
Correct |
2 ms |
5036 KB |
Output is correct |
25 |
Correct |
2 ms |
4948 KB |
Output is correct |
26 |
Correct |
10 ms |
5204 KB |
Output is correct |
27 |
Correct |
4 ms |
5460 KB |
Output is correct |
28 |
Incorrect |
12 ms |
7508 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |