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 ...
随机推荐
- C 可变参数的宏定义
宏定义 也能来可变参数..吼吼..方便好多.. #define T(x,y...) printf(x,##y); C99标准..这我也管不到.... 关键是那个 ... 和 ## 我也不推荐到首页.记 ...
- 【单例模式】Singleton pattern
前言:有很多时候,在一个生命周期中我们只要一个对象就可以了,比如:线程池,缓存,对话框,日志,显卡驱动等等.如果造出多个实例,就会导致许多问题产生,例如:程序的行为异常.资源使用过量,或者说不一致的结 ...
- 博客迁移到http://pengliu.cf
博客迁移到http://pengliu.cf
- Redis 占用Windows系统盘空间23G
Redis常出现问题总结: 1.当出现修改--maxheap and --heapdir 在启动这两个版本时都会创建一个 RedisQFork.dat文件,我不确定 RedisQFork 文件是否变小 ...
- EF 配置实现建表与迁移
通过EF 作为操作数据库的工具有一段时间了,也做了几个相对不大的项目,慢慢的也对EF的使用摸索出来了一些规则,虽然说不是技术难点,但是,我说的是但是,能够提高我们开发效率的棉花糖有时我们还是必须要吃的 ...
- angular component元素
- CENTOS7 使用 Nginx + Uwsgi 部署 Django 项目
写在前面的话 最近总是见到有新学 Django 的朋友在部署自己的项目到 Linux 上面的时候运行不起来,所以就动手写了这篇博客. 对于不会搭建 Python 3 环境的朋友可以参考前面的博客[CE ...
- 小规模kvm宿主机管理-webvirtmgr安装
1.前言WebVirtMgr是近两年来发展较快,比较活跃,非常清新的一个KVM管理平台,提供对宿主机和虚机的统一管理,它有别于kvm自带的图形管理工具(virtual machine manager) ...
- 基于stor2RRD 的 SAN、存储监控
一. 配置用法在官网都有的详见网页: http://www.stor2rrd.com/install.htm?1.2 二 . 在这里我只是想记录一下我是如何编译安装Apache的,避免踩坑: 安装包如 ...
- 题解 UVA10212 【The Last Non-zero Digit.】
题目链接 这题在学长讲完之后和看完题解之后才明白函数怎么构造. 这题构造一个$f(n)$ $f(n)$ $=$ $n$除以 $2^{a}$ $*$ $5^{b}$ ,$a$ , $b$ 分别是 $n$ ...