105752024-04-05 19:53:38111Branch Cuttingcpp17Runtime error 0/1002.078s523688 KiB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N,K1,K2;
	cin>>N>>K1>>K2;
	vector<vector<int>>g(N+1);
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int ans=0;
	auto dfs=[&](auto self,int i,int p,int d)->ordered_multiset<int>{
		ordered_multiset<int>s;
		s.insert(d);
		for(int j:g[i]){
			if(j==p){
				continue;
			}
			auto z=self(self,j,i,d+1);
			if(s.size()<z.size()){
				swap(s,z);
			}
			for(int x:z){
				ans+=s.order_of_key(K2+d*2-x+1)-s.order_of_key(K1+d*2-x);
			}
			for(int x:z){
				s.insert(x);
			}
		}
		return s;
	};
	dfs(dfs,1,0,0);
	cout<<ans<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error3ms2256 KiB
2Wrong answer3ms2216 KiB
subtask20/8
3Runtime error3ms2400 KiB
4Wrong answer3ms2700 KiB
5Runtime error3ms2856 KiB
6Runtime error3ms3220 KiB
7Runtime error3ms3228 KiB
8Runtime error3ms2996 KiB
9Runtime error3ms3248 KiB
10Runtime error3ms3192 KiB
11Runtime error3ms3192 KiB
subtask30/15
12Runtime error263ms523688 KiB
13Runtime error264ms523656 KiB
14Runtime error272ms523544 KiB
15Runtime error305ms523324 KiB
16Runtime error259ms523176 KiB
17Time limit exceeded2.078s27460 KiB
18Time limit exceeded2.066s29672 KiB
subtask40/10
19Runtime error3ms3864 KiB
20Wrong answer13ms3988 KiB
21Runtime error3ms4012 KiB
22Runtime error3ms4120 KiB
23Runtime error3ms4352 KiB
24Runtime error3ms4444 KiB
25Runtime error3ms4320 KiB
26Runtime error3ms4480 KiB
subtask50/25
27Runtime error3ms4760 KiB
28Wrong answer601ms6760 KiB
29Runtime error3ms4856 KiB
30Runtime error3ms4808 KiB
31Runtime error3ms4700 KiB
32Runtime error3ms4720 KiB
33Runtime error3ms4868 KiB
34Runtime error3ms5156 KiB
subtask60/42
35Runtime error6ms14188 KiB
36Time limit exceeded2.078s12904 KiB
37Runtime error6ms13872 KiB
38Runtime error7ms14100 KiB
39Runtime error7ms14332 KiB
40Runtime error7ms14292 KiB
41Runtime error7ms14208 KiB
42Runtime error7ms14208 KiB
43Runtime error7ms14208 KiB