HDU5137-最短路-删点
How Many Maos Does the Guanxi Worth
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 3290 Accepted Submission(s): 1291
Here is an example. In many cities in China, the government prohibit the middle school entrance examinations in order to relief studying burden of primary school students. Because there is no clear and strict standard of entrance, someone may make their children enter good middle schools through guanxis. Boss Liu wants to send his kid to a middle school by guanxi this year. So he find out his guanxi net. Boss Liu's guanxi net consists of N people including Boss Liu and the schoolmaster. In this net, two persons who has a guanxi between them can help each other. Because Boss Liu is a big money(In Chinese English, A "big money" means one who has a lot of money) and has little friends, his guanxi net is a naked money guanxi net -- it means that if there is a guanxi between A and B and A helps B, A must get paid. Through his guanxi net, Boss Liu may ask A to help him, then A may ask B for help, and then B may ask C for help ...... If the request finally reaches the schoolmaster, Boss Liu's kid will be accepted by the middle school. Of course, all helpers including the schoolmaster are paid by Boss Liu.
You hate Boss Liu and you want to undermine Boss Liu's plan. All you can do is to persuade ONE person in Boss Liu's guanxi net to reject any request. This person can be any one, but can't be Boss Liu or the schoolmaster. If you can't make Boss Liu fail, you want Boss Liu to spend as much money as possible. You should figure out that after you have done your best, how much at least must Boss Liu spend to get what he wants. Please note that if you do nothing, Boss Liu will definitely succeed.
For each test case:
The first line contains two integers N and M. N means that there are N people in Boss Liu's guanxi net. They are numbered from 1 to N. Boss Liu is No. 1 and the schoolmaster is No. N. M means that there are M guanxis in Boss Liu's guanxi net. (3 <=N <= 30, 3 <= M <= 1000)
Then M lines follow. Each line contains three integers A, B and C, meaning that there is a guanxi between A and B, and if A asks B or B asks A for help, the helper will be paid C RMB by Boss Liu.
The input ends with N = 0 and M = 0.
It's guaranteed that Boss Liu's request can reach the schoolmaster if you do not try to undermine his plan.
1 2 3
1 3 7
1 4 50
2 3 4
3 4 2
3 2
1 2 30
2 3 10
0 0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<functional>
using namespace std;
#define LL long long
#define pii pair<int,int>
#define mp make_pair
#define inf 0x3f3f3f3f
struct Edge{
int v,w,next;
}e[];
int first[],tot;
void add(int u,int v,int w){
e[tot].v=v;
e[tot].w=w;
e[tot].next=first[u];
first[u]=tot++;
}
int vis[],d[],n,m;
void dij(int no){
memset(vis,,sizeof(vis));
memset(d,inf,sizeof(d));
priority_queue<pii,vector<pii>,greater<pii> >q;
d[]=;
q.push(mp(,));
while(!q.empty()){
int u=q.top().second;
q.pop();
if(vis[u]) continue;
vis[u]=;
for(int i=first[u];i+;i=e[i].next){
if(e[i].v==no) continue;
if(d[e[i].v]>d[u]+e[i].w){
d[e[i].v]=d[u]+e[i].w;
q.push(mp(d[e[i].v],e[i].v));
}
}
}
}
int main()
{
int i,j,k,ans;
int u,v,w;
while(cin>>n>>m&&(n||m)){ans=-;
memset(first,-,sizeof(first));
tot=;
while(m--){
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
for(i=;i<n;++i){
dij(i);
ans=max(ans,d[n]);
}
if(ans==inf) puts("Inf");
else cout<<ans<<endl;
}
return ;
}
Inf
HDU5137-最短路-删点的更多相关文章
- HDU1595-最短路-删边
find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others) Memory Limit: 32768/32768 ...
- Codeforces Round #302 (Div. 2) D. Destroying Roads 最短路 删边
题目:有n个城镇,m条边权为1的双向边让你破坏最多的道路,使得从s1到t1,从s2到t2的距离分别不超过d1和d2. #include <iostream> #include <cs ...
- 【转】最短路&差分约束题集
转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...
- 转载 - 最短路&差分约束题集
出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★ ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- SGU185 - Two Shortest
原题地址:http://acm.sgu.ru/problem.php?contest=0&problem=185 题目大意:给出一个无向图,求出从 1 到 n 的两条没有相同边的最短路径(允许 ...
- NOIP算法总结
前言 离NOIP还有一个星期,匆忙的把寒假整理的算法补充完善,看着当时的整理觉得那时还年少.第二页贴了几张从贴吧里找来的图片,看着就很热血的.旁边的同学都劝我不要再放PASCAL啊什么的了,毕竟我们的 ...
- 冲刺NOIP复习,算法知识点总结
前言 离NOIP还有一个星期,匆忙的把整理的算法补充完善,看着当时的整理觉得那时还年少.第二页贴了几张从贴吧里找来的图片,看着就很热血的.当年来学这个竞赛就是为了兴趣,感受计算机之美的. ...
- 【HDOJ图论题集】【转】
=============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...
随机推荐
- (转)extern关键字两种场景的使用
第一种场景 -- extern extern关键字的作用是声明变量和函数为外部链接,即该变量或函数名在其它文件中可见.用其声明的变量或函数应该在别的文件或同一文件的其它地方定义. 例如语句:exter ...
- [转]运动检测(前景检测)之(二)混合高斯模型GMM
转自:http://blog.csdn.net/zouxy09/article/details/9622401 因为监控发展的需求,目前前景检测的研究还是很多的,也出现了很多新的方法和思路.个人了解的 ...
- redis数据持久化内存不足
原因:写数据到redis里面写不进去,查看redis日志显示: Can't save in background: fork: Cannot allocate memory 在小内存的进程上做一个fo ...
- tomcat源码调试
三.tomcat目录结构 tomcat的下载安装有很多教程,不再赘述. 现在的tomcat已经到9了,当tomcat下载安装完成后,其目录大致如下: 除了上面的文件夹,还有四个文件: ...
- iOS开发之XMPPFramework环境搭建和配置
1.mysql数据库安装和配置 官方下载地址:http://www.mysql.com/downloads/ 百度云盘地址: 安装软件参考:http://www.cnblogs.com/macro-c ...
- selenium 之定位方法
1 id 定位 driver.find_element_by_id() HTML 规定id 属性在HTML 文档中必须是唯一的.这类似于公民的身份证号,具有很强的唯一性 from selenium i ...
- PentestBox简明使用教程
介绍 PentestBox:渗透测试盒子 顾名思义,这是一个渗透工具包,但是不同于绝大多数国内xx工具包的是,这里集成的大都是Linux下的工具,Kali Linux上面的常用的很多工具这里面也都集成 ...
- php项目代码 编码格式不对会大范围报错
php项目代码 编码格式不对会大范围报错
- 1691: [Usaco2007 Dec]挑剔的美食家
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 621 Solved: 280[Submit][Status][Discuss] Description ...
- [翻译]解读CSS中的长度单位
测量,在WEB设计上是非常重要的.在CSS中有至少10种不同的测量单位.每种单位都有其独特的作用,使用它们,可以使页面,在各种设备上,很好的工作.一旦你熟悉了所有这些单位,你可以更准确地设定元素的大小 ...