104952024-04-03 15:01:19111A Day in Olbiacpp17Wrong answer 0/1005.081s59132 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Accepted3ms2060 KiB
subtask20/16
3Accepted4ms2300 KiB
4Accepted4ms2628 KiB
5Accepted4ms2680 KiB
6Wrong answer4ms3020 KiB
subtask30/16
7Accepted660ms3352 KiB
8Accepted634ms3376 KiB
9Accepted160ms4084 KiB
10Accepted256ms3860 KiB
11Accepted218ms3848 KiB
12Wrong answer172ms4128 KiB
13Wrong answer181ms4220 KiB
14Wrong answer173ms4460 KiB
15Wrong answer165ms4676 KiB
subtask40/16
16Time limit exceeded5.066s17992 KiB
17Time limit exceeded5.071s19096 KiB
subtask50/52
18Time limit exceeded5.081s19772 KiB
19Time limit exceeded5.034s20988 KiB
20Time limit exceeded5.048s45808 KiB
21Time limit exceeded5.076s40852 KiB
22Time limit exceeded5.072s43732 KiB
23Time limit exceeded5.059s45872 KiB
24Time limit exceeded5.052s48964 KiB
25Time limit exceeded5.076s52020 KiB
26Time limit exceeded5.068s53028 KiB
27Time limit exceeded5.057s54252 KiB
28Time limit exceeded5.072s55336 KiB
29Time limit exceeded5.048s56424 KiB
30Time limit exceeded5.065s57716 KiB
31Time limit exceeded5.076s59132 KiB