FZU - 2038 Another Postman Problem
来源:互联网 发布:中国联通4g网络设置 编辑:程序博客网 时间:2024/06/13 22:31
题意:对于每一条边,它的访问次数等于它子树的节点个数*剩余的节点个数
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;const int MAXN = 100010;struct node{ int v,w; node(){} node(int a,int b){ v = a; w = b; }};int vis[MAXN],T,n;vector<node> G[MAXN];long long ans;long long cal(int u){ vis[u] = 1; int size = G[u].size(); long long sum = 1,temp; for (int i = 0; i < size; i++){ int v = G[u][i].v; if (vis[v]) continue; temp = cal(v); ans += 2 * G[u][i].w * temp * (n-temp); sum += temp; } return sum;}int main(){ int t,u,v,w,cas=1; scanf("%d",&t); while (t--){ for (int i = 0; i < MAXN; i++) G[i].clear(); memset(vis,0,sizeof(vis)); scanf("%d",&n); for (int i = 1; i < n; i++){ scanf("%d%d%d",&u,&v,&w); G[u].push_back(node(v,w)); G[v].push_back(node(u,w)); } ans = 0; cal(0); printf("Case %d: %lld\n",cas++,ans); } return 0;}
0 0
- FZU - 2038 Another Postman Problem
- fzu 2038 Another Postman Problem(递归求解)
- fzu 2038 Another Postman Problem(dfs)
- FZU 2038 Another Postman Problem【思维】
- fzu 2038 Another Postman Problem 递归
- fzu2038 Another Postman Problem
- Another Easy Problem FZU
- fzu 1753 Another Easy Problem
- FZU2038 Another Postman Problem 树状DP
- Another Postman Problem (邻接表+DFS)
- FZU2011年全国大学生程序设计邀请赛(福州) 2038Another Postman Problem
- FZU 1753:Another Easy Problem _素因子分解
- FZU 1753-Another Easy Problem(求多个组合数的最大公约数)
- Another a+b FZU
- 【解题报告】fzu 1753 Another Easy Problem - 求150个组合数的最大公约数
- fzu 1753 Another Easy Problem(n!的素因子分解)
- FZU 1753 Another Easy Problem 解题报告(素因子统计)
- fzu-1753 Another Easy Problem-快速求N!中有多少个p
- 几款国产开源的Windows界面库
- 林老师最后一次大作业的要求翻译:Project 10 – RTSP Windows Client: RFC 2326
- 利用Javascript通过WMI取得Windows系统信息
- 大数据统计分析公司介绍-决策树
- 数据结构 二叉排序树
- FZU - 2038 Another Postman Problem
- 判断二叉树是否为二叉搜索树BST
- jbpm4.4集成入SSH项目中
- poj 1276 Cash Machine
- Finagle:一个支持多协议的RPC系统
- 实现物体的方向跟着拖拽的方向
- yum 命令
- Launcher2<一>
- Hadoop、HBase配置Ganglia指南(metrics1)