HDU 4171 Paper Route
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?
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.)
1
3
4
0 1 1
0 2 2
树的性质:从跟节点出发遍历一颗树的所有节点再回到跟节点的花费为一定为他的所有的权值之和的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的更多相关文章
- hdu4171 Paper Route 树的性质+DFS
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4171 题意: 有n+1个点,这n+1个点由n条边相连,且保证连通.然后给出各个点到出口的距离,要求从 ...
- hdu 4171 最短路
#include<stdio.h> #include<string.h> #include<queue> #include<iostream> usin ...
- hdu 2680 Choose the best route
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2680 Choose the best route Description One day , Kiki ...
- hdu 5224 Tom and paper
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5224 Tom and paper Description There is a piece of pa ...
- hdu 4240 Route Redundancy 最大流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4240 A city is made up exclusively of one-way steets. ...
- HDU 5224 Tom and paper(最小周长)
HDU 5224 Tom and paper(最小周长) Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d &a ...
- [hdu P1599] find the mincost route
[hdu P1599] find the mincost route 杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V ...
- 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 ...
- HDU 2164 Rock, Paper, or Scissors?
http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...
随机推荐
- 在iis7.5上部署asp.net mvc5
部署mvc5跟部署mvc4是一样的,唯一不同的是需要修改一下web.config的配置 在web.config中加入一下节点即可 <system.webServer> <module ...
- uoj#344. 【清华集训2017】我的生命已如风中残烛(计算几何)
题面 传送门 题解 orzxyx 首先我们发现,一个点如果被到达大于一次,那么这个点肯定在一个环上.所以在不考虑环的情况下每个点只会被到达一次,那么我们就可以直接暴力了 简单来说,我们对每个点\(i\ ...
- 第八届山东ACM省赛F题-quadratic equation
这个题困扰了我长达1年多,终于在今天下午用两个小时理清楚啦 要注意的有以下几点: 1.a=b=c=0时 因为x有无穷种答案,所以不对 2.注意精度问题 3.b^2-4ac<0时也算对 Probl ...
- Reviewing notes 1.1 of Analytic geometry
Chapter 1 Vector Algebra ♦ Vector Space Vector and vector space A vector is described as a quantity ...
- 浅谈PHP的Public、Protected、Private三种方法的区别
public:权限是最大的,可以内部调用,实例调用等.protected: 受保护类型,用于本类和继承类调用.private: 私有类型,只有在本类中使用. <?php error_report ...
- 高版本sketch文件转成低版本的sketch
https://pan.baidu.com/s/1htmNERU 下载 该文件然后在放到高版本sketch文件的目录下,执行下面命令 chmod +x ./build.sh ./build.sh 文件 ...
- js 自定义属性
html标签中有没有什么自带的属性可以存储成绩的----没有 本身html标签没有这个属性,自己(程序员)添加的,----自定义属性---为了存储一些数据 在html标签中添加的自定义属性,如果 ...
- ASP.NET后台取html控件值方式
1.Request.Form[“cbName”]: 可以在后台取到所有为name 为的控件的value值 2.可以通过 把html控件的值付给HiddenField,然后后台调用 3.就是自定义属性 ...
- java 关于数组 计数的面试题
题目:用面向对象的方法求出数组中重复 value 的个数 : 1 出现:1 次3 出现:2 次8 出现:3 次2 出现:4 提供数组 : int[] arr = {1,4,1,4,2,5,4,5 ...
- C++_类继承5-抽象基类
abstract base class,ABC 抽象基类 有时候is-a规则并不像看上去那么简单,例如圆和椭圆的关系.圆是椭圆的特殊情况.椭圆可以派生出圆.但是椭圆的数据成员及方法对于圆来说是信息冗余 ...