Problem Description
As a poor, tuition-ridden student, you've decided to take up a part time job as a paperboy/papergirl.
You've just been handed your paper route: a set of addresses (conveniently labelled 1 to N).

Every
morning, you start at the newspaper office (which happens to be address
number 0). You have to plan a route to deliver a newspaper to every
address - and you also want to get to class right after you're done.
Conveniently, there are only N roads in your area connecting the addresses, and each of them takes a known time to traverse.
Also,
you've precalculated the time it takes to get to Waterloo campus from
each address, including the newspaper office (through some combination
of biking, busing, or hitching a ride).
How soon can you be done delivering papers and be in your seat at school?

 
Input
Input consists of a number of cases, for each case:
First, there will be a single integer N (the number of addresses, 1 ≤ N ≤ 100,000).
Next, there will be N+1 lines, each with an integer ci (starting with i = 0, 0 ≤ ci ≤ 1,000,000,000), the time it takes to get from location i to campus.
Finally,
the input will contain N lines, each with three integers a, b, c (0 ≤
a, b ≤ N, a != b, 0 ≤ c ≤ 1,000). Each of these lines describes a road
between locations a and b taking c minutes to traverse.
It is guaranteed that you will be able to reach all the addresses. (Remember that location 0 is the newspaper office.)
 
Output
Output the minimum time it will take to deliver all the papers and get to class.
 
Sample Input
2
1
3
4
0 1 1
0 2 2
Sample Output
7
 
Source

树的性质:从跟节点出发遍历一颗树的所有节点再回到跟节点的花费为一定为他的所有的权值之和的2倍。

 #include <stdio.h>
#include <iostream>
#include <vector>
#define MAXN 110000
using namespace std; struct Node{
int end;
int w;
}; int N;
int dist[MAXN];
bool visited[MAXN];
vector<Node> V[MAXN];
__int64 c[MAXN];
__int64 sum; void addEdge(int u ,int v, int w){
Node n1,n2;
n1.end=v;
n1.w=w;
V[u].push_back(n1);
n2.end=u;
n2.w=w;
V[v].push_back(n2);
} void dfs( int u ){
int size=V[u].size();
for(int i=; i<size; i++){
Node now=V[u][i];
if( !visited[now.end] ){
dist[now.end]=dist[u]+now.w;
sum+=now.w;
visited[now.end]=;
dfs(now.end);
}
}
} int main()
{
while( scanf("%d",&N)!=EOF ){
for(int i=; i<=N; i++){
scanf("%I64d" ,&c[i]);
}
for(int i=; i<=N; i++){
V[i].clear();
}
memset(dist , ,sizeof(dist));
memset(visited , ,sizeof(visited));
int u,v,w;
for(int i=; i<=N; i++){
scanf("%d %d %d" ,&u ,&v ,&w);
addEdge(u ,v ,w);
}
sum=;
visited[]=;
dfs();
__int64 ans=*sum;
__int64 min=*sum+c[];
for(int i=; i<=N; i++){
if( ans-dist[i]+c[i]<min )
min=ans-dist[i]+c[i];
}
printf("%I64d\n" ,min);
}
return ;
}

HDU 4171 Paper Route的更多相关文章

  1. hdu4171 Paper Route 树的性质+DFS

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4171 题意: 有n+1个点,这n+1个点由n条边相连,且保证连通.然后给出各个点到出口的距离,要求从 ...

  2. hdu 4171 最短路

    #include<stdio.h> #include<string.h> #include<queue> #include<iostream> usin ...

  3. hdu 2680 Choose the best route

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Description One day , Kiki ...

  4. hdu 5224 Tom and paper

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5224 Tom and paper Description There is a piece of pa ...

  5. hdu 4240 Route Redundancy 最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4240 A city is made up exclusively of one-way steets. ...

  6. HDU 5224 Tom and paper(最小周长)

    HDU 5224 Tom and paper(最小周长) Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d &a ...

  7. [hdu P1599] find the mincost route

    [hdu P1599] find the mincost route 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V ...

  8. HDU 1599 find the mincost route(floyd求最小环 无向图)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1599 find the mincost route Time Limit: 1000/2000 MS ...

  9. HDU 2164 Rock, Paper, or Scissors?

    http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...

随机推荐

  1. git vs sourcetree

    SourceTree&Git部分名词解释 克隆(clone):从远程仓库URL加载创建一个与远程仓库一样的本地仓库 提交(commit):将暂存文件上传到本地仓库(我们在Finder中对本地仓 ...

  2. windows下go编码转换问题

    github上有两个package做编码转换,都是基于iconv,用到了cgo,在linux下没有问题,在windows下用,非常麻烦.采用mingw安装libiconv也不行,一直提示找不到libi ...

  3. #论文笔记# [pix2pixHD] High-Resolution Image Synthesis and Semantic Manipulation with Conditional GANs

    Ting-Chun Wang, Ming-Yu Liu, Jun-Yan Zhu, Andrew Tao, Jan Kautz, and Bryan Catanzaro. "High-Res ...

  4. f(!gotop.length) return false;

    if (!$("p").length) return; if语句接收一个布尔值,如果布尔值为true则执行接下来的语句,布尔值为false则执行else关键词后的语句. JavaS ...

  5. ClickOnce发布包含某文件

    第一步.在文件上右键选择“属性”,“复制到输出目录”选择“始终复制”: 第二步.“生成操作”选择“选择”: 第三步.通过 项目右键属性-发布-应用程序文件 查看想要包含的文件是否包含进来了. 注:可以 ...

  6. winform程序使用clickonce方式发布之后点击安装没反应

    可能是少了index.html和web.config两个文件,这两个文件为什么没有在发布的时候生成,还有怎么影响安装的后续研究

  7. elasticsearch添加head插件

    首先,肯定是安装elasticsearch啦,我这里是直接在官网上下载rpm包安装的. 官网:https://www.elastic.co/downloads/elasticsearch elasti ...

  8. JDBC记录

    13:55 2018/7/22 用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问 ---------常用API--------- |- Driver接口: 表示java驱动程序接 ...

  9. word的样式设置

    一般自己写文档就用typora了,便捷美观,但是在工作上又不得不用word写文档,我对审美.格式比较有强迫症,有的小公司没有形成自己的文档规范,或者所谓的规范也只是写好了格式的文档,你往里面填内容就可 ...

  10. Apache htaccess 设置....

    NC: no case,就是说不区分大小写R:redirect,重定向F:forbidden,禁止访问L:last,表示已经是最后一条规则,.htaccess文件解析即将退出 比如原地址为 /beau ...