比赛 |
不平凡的世界 |
评测结果 |
AAAAAAAAAA |
题目名称 |
不平凡的许愿树 |
最终得分 |
100 |
用户昵称 |
---- |
运行时间 |
3.148 s |
代码语言 |
C++ |
内存使用 |
0.50 MiB |
提交时间 |
2015-11-05 09:58:17 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
template<class T> inline void mint(T& a, T b) { if (a > b) a = b; }
template<class T> inline void maxt(T& a, T b) { if (a < b) a = b; }
typedef long long int i64;
#ifdef WINVER
#define QAQ "%I64d"
#else
#define QAQ "%lld"
#endif
const int maxn = 5333;
#define time youginzi
int n; i64 f[2][maxn];
int vis[maxn], cnt[maxn], time, mdep = 0;
vector<int> G[maxn];
void dfs(int u, int fa, int dep)
{
if (vis[dep] != time) vis[dep] = time, cnt[dep] = 1;
else ++cnt[dep];
maxt(mdep, dep);
for (vector<int>::iterator p = G[u].begin();
p != G[u].end(); ++p) if (*p != fa) dfs(*p, u, dep + 1);
}
int main()
{
freopen("hopetree.in", "r", stdin);
#ifndef debug
freopen("hopetree.out", "w", stdout);
#endif
scanf("%d", &n);
for (int i = 1; i < n; ++i)
{
int u, v; scanf("%d%d", &u, &v);
G[u].push_back(v); G[v].push_back(u);
}
i64 ans = 0;
for (int i = 1; i <= n; ++i)
{
memset(f, 0, sizeof(f));
for (vector<int>::iterator p = G[i].begin();
p != G[i].end(); ++p)
{
++time; mdep = 0; dfs(*p, i, 1);
for (int j = 1; j <= mdep; ++j)
{
ans += f[1][j] * cnt[j];
f[1][j] += f[0][j] * cnt[j];
f[0][j] += cnt[j];
}
}
}
printf(QAQ" "QAQ"\n", ans % 338 + 1, (ans + 233) % 338 + 1);
}