HDU5137 How Many Maos Does the Guanxi Worth(最短路,spfa)
来源:互联网 发布:starstail mac 安装 编辑:程序博客网 时间:2024/05/21 18:38
题目:
How Many Maos Does the Guanxi Worth
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total Submission(s): 2618 Accepted Submission(s): 1019
Problem Description
"Guanxi" is a very important word in Chinese. It kind of means "relationship" or "contact". Guanxi can be based on friendship, but also can be built on money. So Chinese often say "I don't have one mao (0.1 RMB) guanxi with you." or "The guanxi between them is naked money guanxi." It is said that the Chinese society is a guanxi society, so you can see guanxi plays a very important role in many things.
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.
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.
Input
There are several test cases.
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.
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.
Output
For each test case, output the minimum money Boss Liu has to spend after you have done your best. If Boss Liu will fail to send his kid to the middle school, print "Inf" instead.
Sample Input
4 51 2 31 3 71 4 502 3 43 4 23 21 2 302 3 100 0
Sample Output
50Inf
Source
2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大)
Recommend
liuyiding | We have carefully selected several similar problems for you: 6022 6021 6020 6019 6018
给了n个点m条边然后给出了各个边的权值,然后想要从第一个点走到最后一个点,你可以使某一个点失效,增加刘老板从第一个点走到最后一个点的难度,然后在求最短路,如果走不到输出Inf,因为顶点数不多,所以可以用邻接矩阵建图,然后在把每一个点spfa一遍,从里面找出最大的就好
代码:
#include <cstdio>#include <cstring>#include <cctype>#include <string>#include <set>#include <iostream>#include <stack>#include <cmath>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define mod 10000007#define debug() puts("what the fuck!!!")#define N 1200#define M 1000000#define ll long longusing namespace std;int map[50][50];int vis[50];int dis[50];int n,m;void spfa(int p){ queue<int>q; mem(vis,0); for(int i=1; i<=n; i++) dis[i]=inf; vis[1]=1; dis[1]=0; q.push(1); while(!q.empty()) { int k=q.front(); vis[k]=0; q.pop(); for(int i=1; i<=n; i++) { int w=map[k][i]; if(i==p||k==p) w=inf; if(dis[k]+w<dis[i]) { dis[i]=dis[k]+w; if(!vis[i]) { vis[i]=1; q.push(i); } } } }}int main(){ int a,b,c; while(scanf("%d%d",&n,&m)&&n&&m) { mem(map,inf); for(int i=1; i<=m; i++) { scanf("%d%d%d",&a,&b,&c); if(map[a][b]>c) map[a][b]=c; if(map[b][a]>c) map[b][a]=c; } int maxx=0; for(int i=2; i<n; i++) { spfa(i); maxx=max(maxx,dis[n]); } if(maxx==inf) puts("Inf"); else printf("%d\n",maxx); } return 0;}
0 0
- 【最短路】HDU5137 How Many Maos Does the Guanxi Worth
- HDU5137 How Many Maos Does the Guanxi Worth(最短路,spfa)
- HDU5137-最短路最大化-How Many Maos Does the Guanxi Worth
- hdu5137 How Many Maos Does the Guanxi Worth
- HDU5137 How Many Maos Does the Guanxi Worth
- HDU 5137--How Many Maos Does the Guanxi Worth【枚举 && 最短路 && spfa】
- HDU5137 How Many Maos Does the Guanxi Worth (14广州现场赛K题 )--最短路问题
- hdoj5137How Many Maos Does the Guanxi Worth【最短路】
- hdu5137How Many Maos Does the Guanxi Worth【最短路最大值】
- HDU5137How Many Maos Does the Guanxi Worth(最短路)
- How Many Maos Does the Guanxi Worth
- How Many Maos Does the Guanxi Worth
- How Many Maos Does the Guanxi Worth
- How Many Maos Does the Guanxi Worth
- How Many Maos Does the Guanxi Worth
- How Many Maos Does the Guanxi Worth
- hdoj 5137 How Many Maos Does the Guanxi Worth【最短路】
- HDU 5137 How Many Maos Does the Guanxi Worth (14广州 Floyd 最短路)
- MySQL逻辑架构及性能优化原理
- CSU 1093 Caps Lock (贪心+模拟)
- iOS 保存图片到相册
- NOIP2012 D2T1
- linux下怎样安装openmpi
- HDU5137 How Many Maos Does the Guanxi Worth(最短路,spfa)
- Linux下.tgz、.rpm等软件包的常用安装方法
- css 修改placeholder的颜色
- [小题大做] Github + Jenkins 实现自动化部署 hexo 博客静态文件
- 正向代理与反向代理【总结】
- STM32F103ZET6学习笔记(1)---CM3基础
- Mybatis整合spring
- Android设计模式-观察者模式
- python创建命令行地址簿程序