比赛 不平凡的世界 评测结果 EAAAAETTTT
题目名称 不平凡的许愿树 最终得分 40
用户昵称 Binary10 运行时间 25.065 s
代码语言 C++ 内存使用 97.88 MiB
提交时间 2015-11-05 11:52:28
显示代码纯文本
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int MOD = 338;
const int maxn = 5010;
int a[maxn][maxn], n;
int main()
{
  freopen("hopetree.in", "r", stdin);
  freopen("hopetree.out", "w", stdout);
  scanf("%d", &n);
  memset(a, -1, sizeof(a));
  int u, v;
  for(int i = 1; i <= n - 1; i++){
    scanf("%d%d", &u, &v);
    a[u][v] = a[v][u] = 1;
  }
  for(int i = 1; i <= n; i++) 
    a[i][i] = 0;
  for(int k = 1; k <= n; k++)
    for(int i = 1; i <= n; i++)
      for(int j = 1; j <= n; j++)
        if(a[i][k] != -1 && a[k][j] != -1)
          if(a[i][j] == -1) a[i][j] = a[i][k] + a[k][j];
          else a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
  int cnt = 0;
  for(int i = 1; i <= n - 2; i++)
    for(int j = i + 1; j <= n - 1; j++)
      for(int k = j + 1; k <= n; k++)
        if(a[i][j] == a[i][k] && a[i][j] == a[j][k])
          cnt = (cnt + 1) % MOD;
  printf("%d %d\n", cnt + 1, (cnt + 233) % MOD + 1); 
  return 0;
}