10496 | 2024-04-03 15:03:39 | 111 | A Day in Olbia | cpp17 | Wrong answer 0/100 | 667ms | 4992 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<=N;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*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,0,-1,0);
}
cout<<ans<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1832 KiB | ||||
2 | Accepted | 3ms | 2060 KiB | ||||
subtask2 | 0/16 | ||||||
3 | Accepted | 4ms | 2284 KiB | ||||
4 | Accepted | 4ms | 2652 KiB | ||||
5 | Accepted | 4ms | 2956 KiB | ||||
6 | Wrong answer | 4ms | 3180 KiB | ||||
subtask3 | 0/16 | ||||||
7 | Accepted | 667ms | 3264 KiB | ||||
8 | Accepted | 648ms | 3336 KiB | ||||
9 | Accepted | 160ms | 3912 KiB | ||||
10 | Accepted | 232ms | 4076 KiB | ||||
11 | Accepted | 204ms | 4592 KiB | ||||
12 | Wrong answer | 172ms | 4720 KiB | ||||
13 | Wrong answer | 181ms | 4696 KiB | ||||
14 | Wrong answer | 175ms | 4912 KiB | ||||
15 | Wrong answer | 166ms | 4992 KiB | ||||
subtask4 | 0/16 | ||||||
16 | Runtime error | 3ms | 4368 KiB | ||||
17 | Runtime error | 2ms | 4364 KiB | ||||
subtask5 | 0/52 | ||||||
18 | Runtime error | 3ms | 4600 KiB | ||||
19 | Runtime error | 3ms | 4576 KiB | ||||
20 | Runtime error | 2ms | 4444 KiB | ||||
21 | Runtime error | 2ms | 4436 KiB | ||||
22 | Runtime error | 2ms | 4580 KiB | ||||
23 | Runtime error | 2ms | 4564 KiB | ||||
24 | Runtime error | 3ms | 4664 KiB | ||||
25 | Runtime error | 3ms | 4560 KiB | ||||
26 | Runtime error | 3ms | 4568 KiB | ||||
27 | Runtime error | 2ms | 4656 KiB | ||||
28 | Runtime error | 2ms | 4648 KiB | ||||
29 | Runtime error | 2ms | 4648 KiB | ||||
30 | Runtime error | 2ms | 4648 KiB | ||||
31 | Runtime error | 2ms | 4648 KiB |