10500 | 2024-04-03 15:52:06 | 111 | A Day in Olbia | cpp17 | Runtime error 32/100 | 8ms | 5116 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
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;
auto dfs=[&](auto self,int i,int p,int d)->map<pair<int,int>,int>{
map<pair<int,int>,int>s;
for(int m=1;i*m<=N&&m<=N;m++){
s[{m,i*m-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(auto[mx,y]:z){
auto[m,x]=mx;
auto t=s.find({m,-x-d*2});
if(t!=s.end()){
ans+=t->second*y;
}
}
for(auto[mx,y]:z){
s[mx]+=y;
}
}
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 | 2048 KiB | ||||
subtask2 | 16/16 | ||||||
3 | Accepted | 3ms | 2464 KiB | ||||
4 | Accepted | 3ms | 2632 KiB | ||||
5 | Accepted | 3ms | 2588 KiB | ||||
6 | Accepted | 3ms | 3044 KiB | ||||
subtask3 | 16/16 | ||||||
7 | Accepted | 8ms | 4428 KiB | ||||
8 | Accepted | 8ms | 4036 KiB | ||||
9 | Accepted | 6ms | 4528 KiB | ||||
10 | Accepted | 6ms | 4496 KiB | ||||
11 | Accepted | 7ms | 4720 KiB | ||||
12 | Accepted | 7ms | 4880 KiB | ||||
13 | Accepted | 7ms | 4892 KiB | ||||
14 | Accepted | 6ms | 5116 KiB | ||||
15 | Accepted | 6ms | 5080 KiB | ||||
subtask4 | 0/16 | ||||||
16 | Runtime error | 3ms | 3628 KiB | ||||
17 | Runtime error | 3ms | 3660 KiB | ||||
subtask5 | 0/52 | ||||||
18 | Runtime error | 3ms | 3868 KiB | ||||
19 | Runtime error | 3ms | 3984 KiB | ||||
20 | Runtime error | 3ms | 4084 KiB | ||||
21 | Runtime error | 3ms | 4068 KiB | ||||
22 | Runtime error | 3ms | 4296 KiB | ||||
23 | Runtime error | 2ms | 4376 KiB | ||||
24 | Runtime error | 2ms | 4352 KiB | ||||
25 | Runtime error | 2ms | 4360 KiB | ||||
26 | Runtime error | 2ms | 4356 KiB | ||||
27 | Runtime error | 3ms | 4456 KiB | ||||
28 | Runtime error | 3ms | 4464 KiB | ||||
29 | Runtime error | 3ms | 4468 KiB | ||||
30 | Runtime error | 3ms | 4564 KiB | ||||
31 | Runtime error | 3ms | 4784 KiB |