我一蒟蒻,只会爆搜

评测结果
编译成功

测试数据 #0: Accepted, time = 0 ms, mem = 2856 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 2856 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 2856 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 2856 KiB, score = 10
测试数据 #4: Accepted, time = 31 ms, mem = 2856 KiB, score = 10
测试数据 #5: Accepted, time = 31 ms, mem = 2856 KiB, score = 10
测试数据 #6: TimeLimitExceeded, time = 1203 ms, mem = 2848 KiB, score = 0
测试数据 #7: TimeLimitExceeded, time = 1031 ms, mem = 2848 KiB, score = 0
测试数据 #8: TimeLimitExceeded, time = 1140 ms, mem = 2848 KiB, score = 0
测试数据 #9: TimeLimitExceeded, time = 1015 ms, mem = 2848 KiB, score = 0
TimeLimitExceeded, time = 4451 ms, mem = 2856 KiB, score = 60
代码
#include <algorithm>
#include <cstdio>
using namespace std;
int u[200001],v[200001],w[200001],n,sum = 0,Max = -1000000000;
inline void dfs(int start,int now,int tot) {
  if (tot == 2) {
    Max = max(Max,w[start]*w[now]);
    sum += w[start]*w[now];
    sum %= 10007;
    return;
  }
  for (int i = 1;i <= n;i++)
    if (u[i] == now && v[i] != start) dfs(start,v[i],tot+1);
    else if (v[i] == now && u[i] != start) dfs(start,u[i],tot+1);
}
int main() {
  //freopen("link.in","r",stdin);
  //freopen("link.out","w",stdout);
  scanf("%d",&n);
  for (int i = 1;i <= n-1;i++) scanf("%d%d",&u[i],&v[i]);
  for (int i = 1;i <= n;i++) scanf("%d",&w[i]);
  for (int i = 1;i <= n;i++) dfs(i,i,0);
  printf("%d %d",Max,sum);
  return 0;
}

0 条评论

目前还没有评论...

信息

ID
1906
难度
7
分类
图结构 点击显示
标签
递交数
5638
已通过
914
通过率
16%
被复制
9
上传者