10497 | 2024-04-03 15:29:14 | 111 | A Day in Olbia | cpp17 | Runtime error 0/100 | 3ms | 4412 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
int get(map<int,int>&m,int x){
auto t=m.find(x);
return t==m.end()?0:t->second;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
if(N>1000)exit(1);
vector<vector<int>>g(N);
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;
for(int m=1;m<=1;m++){
auto dfs=[&](auto self,int i,int p,int d)->map<int,int>{
map<int,int>s;
for(int j:g[i]){
if(j==p){
continue;
}
auto z=self(self,j,i,d+1);
ans+=get(z,-(i*m-d)-d*2);
if(s.size()<z.size()){
swap(s,z);
}
for(auto[x,y]:z){
ans+=get(s,-x-d*2)*y;
}
for(auto[x,y]:z){
s[x]+=y;
}
}
s[i*m-d]++;
return s;
};
dfs(dfs,8,-1,0);
}
cout<<ans<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Runtime error | 3ms | 1920 KiB | ||||
2 | Runtime error | 3ms | 2116 KiB | ||||
subtask2 | 0/16 | ||||||
3 | Accepted | 3ms | 2240 KiB | ||||
4 | Accepted | 2ms | 2340 KiB | ||||
5 | Accepted | 2ms | 2336 KiB | ||||
6 | Wrong answer | 3ms | 2692 KiB | ||||
subtask3 | 0/16 | ||||||
7 | Accepted | 3ms | 2860 KiB | ||||
8 | Accepted | 3ms | 2784 KiB | ||||
9 | Accepted | 3ms | 3472 KiB | ||||
10 | Accepted | 3ms | 3332 KiB | ||||
11 | Accepted | 3ms | 3376 KiB | ||||
12 | Wrong answer | 3ms | 3712 KiB | ||||
13 | Wrong answer | 3ms | 3460 KiB | ||||
14 | Wrong answer | 3ms | 3384 KiB | ||||
15 | Wrong answer | 3ms | 3424 KiB | ||||
subtask4 | 0/16 | ||||||
16 | Runtime error | 3ms | 3128 KiB | ||||
17 | Runtime error | 2ms | 3016 KiB | ||||
subtask5 | 0/52 | ||||||
18 | Runtime error | 2ms | 3012 KiB | ||||
19 | Runtime error | 3ms | 3244 KiB | ||||
20 | Runtime error | 3ms | 3452 KiB | ||||
21 | Runtime error | 3ms | 3572 KiB | ||||
22 | Runtime error | 3ms | 3652 KiB | ||||
23 | Runtime error | 3ms | 3748 KiB | ||||
24 | Runtime error | 3ms | 3972 KiB | ||||
25 | Runtime error | 3ms | 4060 KiB | ||||
26 | Runtime error | 3ms | 4156 KiB | ||||
27 | Runtime error | 3ms | 4304 KiB | ||||
28 | Runtime error | 2ms | 4304 KiB | ||||
29 | Runtime error | 3ms | 4320 KiB | ||||
30 | Runtime error | 3ms | 4312 KiB | ||||
31 | Runtime error | 3ms | 4412 KiB |