10495 | 2024-04-03 15:01:19 | 111 | A Day in Olbia | cpp17 | Wrong answer 0/100 | 5.081s | 59132 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;
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 | 1824 KiB | ||||
2 | Accepted | 3ms | 2060 KiB | ||||
subtask2 | 0/16 | ||||||
3 | Accepted | 4ms | 2300 KiB | ||||
4 | Accepted | 4ms | 2628 KiB | ||||
5 | Accepted | 4ms | 2680 KiB | ||||
6 | Wrong answer | 4ms | 3020 KiB | ||||
subtask3 | 0/16 | ||||||
7 | Accepted | 660ms | 3352 KiB | ||||
8 | Accepted | 634ms | 3376 KiB | ||||
9 | Accepted | 160ms | 4084 KiB | ||||
10 | Accepted | 256ms | 3860 KiB | ||||
11 | Accepted | 218ms | 3848 KiB | ||||
12 | Wrong answer | 172ms | 4128 KiB | ||||
13 | Wrong answer | 181ms | 4220 KiB | ||||
14 | Wrong answer | 173ms | 4460 KiB | ||||
15 | Wrong answer | 165ms | 4676 KiB | ||||
subtask4 | 0/16 | ||||||
16 | Time limit exceeded | 5.066s | 17992 KiB | ||||
17 | Time limit exceeded | 5.071s | 19096 KiB | ||||
subtask5 | 0/52 | ||||||
18 | Time limit exceeded | 5.081s | 19772 KiB | ||||
19 | Time limit exceeded | 5.034s | 20988 KiB | ||||
20 | Time limit exceeded | 5.048s | 45808 KiB | ||||
21 | Time limit exceeded | 5.076s | 40852 KiB | ||||
22 | Time limit exceeded | 5.072s | 43732 KiB | ||||
23 | Time limit exceeded | 5.059s | 45872 KiB | ||||
24 | Time limit exceeded | 5.052s | 48964 KiB | ||||
25 | Time limit exceeded | 5.076s | 52020 KiB | ||||
26 | Time limit exceeded | 5.068s | 53028 KiB | ||||
27 | Time limit exceeded | 5.057s | 54252 KiB | ||||
28 | Time limit exceeded | 5.072s | 55336 KiB | ||||
29 | Time limit exceeded | 5.048s | 56424 KiB | ||||
30 | Time limit exceeded | 5.065s | 57716 KiB | ||||
31 | Time limit exceeded | 5.076s | 59132 KiB |