104972024-04-03 15:29:14111A Day in Olbiacpp17Runtime error 0/1003ms4412 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error3ms1920 KiB
2Runtime error3ms2116 KiB
subtask20/16
3Accepted3ms2240 KiB
4Accepted2ms2340 KiB
5Accepted2ms2336 KiB
6Wrong answer3ms2692 KiB
subtask30/16
7Accepted3ms2860 KiB
8Accepted3ms2784 KiB
9Accepted3ms3472 KiB
10Accepted3ms3332 KiB
11Accepted3ms3376 KiB
12Wrong answer3ms3712 KiB
13Wrong answer3ms3460 KiB
14Wrong answer3ms3384 KiB
15Wrong answer3ms3424 KiB
subtask40/16
16Runtime error3ms3128 KiB
17Runtime error2ms3016 KiB
subtask50/52
18Runtime error2ms3012 KiB
19Runtime error3ms3244 KiB
20Runtime error3ms3452 KiB
21Runtime error3ms3572 KiB
22Runtime error3ms3652 KiB
23Runtime error3ms3748 KiB
24Runtime error3ms3972 KiB
25Runtime error3ms4060 KiB
26Runtime error3ms4156 KiB
27Runtime error3ms4304 KiB
28Runtime error2ms4304 KiB
29Runtime error3ms4320 KiB
30Runtime error3ms4312 KiB
31Runtime error3ms4412 KiB