记录编号 |
205580 |
评测结果 |
AAAAAAAAAA |
题目名称 |
不平凡的许愿树 |
最终得分 |
100 |
用户昵称 |
pppoooiiizzy |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
3.961 s |
提交时间 |
2015-11-05 16:17:49 |
内存使用 |
0.49 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<set>
#include<map>
#include<deque>
#include<list>
#include<ctime>
#include<cstdlib>
#include<string>
#include<sstream>
#include<iomanip>
const int maxn = 5000 + 100;
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define rep(i, j, k) for(int i = j; i <= k; i++)
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
return x * f;
}
vector<LL>G[maxn];
LL l1[maxn], l2[maxn], t[maxn];
LL ans, Ar, Sa, m, n;
int dfs(int u, int F, int d)
{
t[d]++;
int La = 1;
for(int i = 0; i < G[u].size(); i++) {
int e = G[u][i];
if(e == F) continue;
La = max(La, dfs(e, u, d + 1) + 1);
}
return La;
}
void init()
{
n = read();
rep(i, 1, n - 1) {
Ar = read(), Sa = read();
G[Ar].push_back(Sa);
G[Sa].push_back(Ar);
}
}
int main()
{
freopen("hopetree.in", "r", stdin);
freopen("hopetree.out", "w", stdout);
init();
for(int i = 1; i <= n; i++) {
for(int j = 0; j < G[i].size(); j++) {
int e = G[i][j];
int La = dfs(e, i, 1);
for(int k = 1; k <= La; k++) {
ans += l2[k] * t[k];
l2[k] += l1[k] * t[k];
l1[k] += t[k];
t[k] = 0;
}
}
for(int j = 1; j <= n; j++)
l1[j] = l2[j] = 0;
}
cout<<ans % 338 + 1<<" "<<(ans + 233) % 338 + 1<<endl;
}