10575 | 2024-04-05 19:53:38 | 111 | Branch Cutting | cpp17 | Runtime error 0/100 | 2.078s | 523688 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Runtime error | 3ms | 2256 KiB | ||||
2 | Wrong answer | 3ms | 2216 KiB | ||||
subtask2 | 0/8 | ||||||
3 | Runtime error | 3ms | 2400 KiB | ||||
4 | Wrong answer | 3ms | 2700 KiB | ||||
5 | Runtime error | 3ms | 2856 KiB | ||||
6 | Runtime error | 3ms | 3220 KiB | ||||
7 | Runtime error | 3ms | 3228 KiB | ||||
8 | Runtime error | 3ms | 2996 KiB | ||||
9 | Runtime error | 3ms | 3248 KiB | ||||
10 | Runtime error | 3ms | 3192 KiB | ||||
11 | Runtime error | 3ms | 3192 KiB | ||||
subtask3 | 0/15 | ||||||
12 | Runtime error | 263ms | 523688 KiB | ||||
13 | Runtime error | 264ms | 523656 KiB | ||||
14 | Runtime error | 272ms | 523544 KiB | ||||
15 | Runtime error | 305ms | 523324 KiB | ||||
16 | Runtime error | 259ms | 523176 KiB | ||||
17 | Time limit exceeded | 2.078s | 27460 KiB | ||||
18 | Time limit exceeded | 2.066s | 29672 KiB | ||||
subtask4 | 0/10 | ||||||
19 | Runtime error | 3ms | 3864 KiB | ||||
20 | Wrong answer | 13ms | 3988 KiB | ||||
21 | Runtime error | 3ms | 4012 KiB | ||||
22 | Runtime error | 3ms | 4120 KiB | ||||
23 | Runtime error | 3ms | 4352 KiB | ||||
24 | Runtime error | 3ms | 4444 KiB | ||||
25 | Runtime error | 3ms | 4320 KiB | ||||
26 | Runtime error | 3ms | 4480 KiB | ||||
subtask5 | 0/25 | ||||||
27 | Runtime error | 3ms | 4760 KiB | ||||
28 | Wrong answer | 601ms | 6760 KiB | ||||
29 | Runtime error | 3ms | 4856 KiB | ||||
30 | Runtime error | 3ms | 4808 KiB | ||||
31 | Runtime error | 3ms | 4700 KiB | ||||
32 | Runtime error | 3ms | 4720 KiB | ||||
33 | Runtime error | 3ms | 4868 KiB | ||||
34 | Runtime error | 3ms | 5156 KiB | ||||
subtask6 | 0/42 | ||||||
35 | Runtime error | 6ms | 14188 KiB | ||||
36 | Time limit exceeded | 2.078s | 12904 KiB | ||||
37 | Runtime error | 6ms | 13872 KiB | ||||
38 | Runtime error | 7ms | 14100 KiB | ||||
39 | Runtime error | 7ms | 14332 KiB | ||||
40 | Runtime error | 7ms | 14292 KiB | ||||
41 | Runtime error | 7ms | 14208 KiB | ||||
42 | Runtime error | 7ms | 14208 KiB | ||||
43 | Runtime error | 7ms | 14208 KiB |