hdu 5137 How Many Maos Does the Guanxi Worth 最短路 spfa
How Many Maos Does the Guanxi Worth
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 2139 Accepted Submission(s): 830
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
Inf
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+; queue<int>q;
int n, m;
ll head[N], nex[N], u[N], v[N], w[N], d[N];
bool vis[N]; inline int read_graph(){
scanf("%d%d",&n,&m);
if(n==&&m==)return ;
memset(head, -, sizeof(head));
for(int e=; e<=m; ++e){
scanf("%lld%lld%lld",&u[e],&v[e],&w[e]);
u[e+m]=v[e], v[e+m]=u[e], w[e+m]=w[e];
nex[e] = head[u[e]];
head[u[e]] = e;
nex[e+m] = head[u[e+m]];
head[u[e+m]] = e+m;
}
return ;
} inline void SPFA(int src,int de){
memset(vis, , sizeof(vis));
for(int i=; i<=n; ++i) d[i] = INF;
d[src] = ; q.push(src);
while(!q.empty()){
int u = q.front(); q.pop();
vis[u] = false;
for(int e=head[u]; e!=-; e=nex[e])
if(v[e]!=de&&d[v[e]] > d[u]+w[e])
{
d[v[e]] = d[u] + w[e];
if(!vis[v[e]]){
vis[v[e]] = true;
q.push(v[e]);
}
}
}
} int main(){
int T,cas=;
while(read_graph()==)
{
ll ans=;
for(int i=;i<=n-;i++)
{
SPFA(,i);
ans=max(ans,d[n]);
}
if(ans>=INF) printf("Inf\n");
else printf("%lld\n",ans);
}
return ;
}
hdu 5137 How Many Maos Does the Guanxi Worth 最短路 spfa的更多相关文章
- HDU 5137 How Many Maos Does the Guanxi Worth 最短路 dijkstra
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- HDU 5137 How Many Maos Does the Guanxi Worth
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5120 ...
- hdoj 5137 How Many Maos Does the Guanxi Worth【最短路枚举+删边】
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- (hdoj 5137 floyd)How Many Maos Does the Guanxi Worth
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- HDU5137 How Many Maos Does the Guanxi Worth(枚举+dijkstra)
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- How Many Maos Does the Guanxi Worth
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- 杭电5137How Many Maos Does the Guanxi Worth
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- ACM学习历程——HDU5137 How Many Maos Does the Guanxi Worth(14广州10题)(单源最短路)
Problem Description "Guanxi" is a very important word in Chinese. It kind of means &quo ...
- hdu5137 How Many Maos Does the Guanxi Worth(单源最短路径)
题目链接:pid=5137">点击打开链接 题目描写叙述:如今有一张关系网.网中有n个结点标号为1-n.有m个关系,每一个关系之间有一个权值.问从2-n-1中随意去掉一个结点之后,从1 ...
随机推荐
- eclipse 利用已有c++代码建工程,并编译执行
如果你想建一个带Makefile的c++ 工程 1. 新建一个C++空工程,工程类型是makefile project,选择Linux GCC: 2. 将源码连同makefile文件一同作为一个文件系 ...
- 【JQGRID DOCUMENTATION】.学习笔记.3.Pager
处理大量数据时,一次只想显示一小部分.这时就需要Navigation Bar.目前Pager不能用于TreeGrid. 定义 }); 定义高度grid,pager是grid的一部分,宽度等于gird的 ...
- 身为运维工程师怎么用Nginx部署DokuWiki
运维人员按区域组织,人员分散,集中培训成本比较高: 新入职运维人员除了培训手册,没有其它渠道可以持续深入了解公司产品: 运维人员的知识存在各自脑袋里,缺少有效的渠道来传播和分享: 运维知识体系需要积累 ...
- PHP中判断字符串是否含有中文
<?php /** * [1.测试一] * 当$str = '中文测试'; 时输出"全部是汉字";当$str = '中a文3测试'; 时输出"不全是汉字" ...
- linux下对sh文件的操作
1.创建test.sh文件 touch test.sh 2.编辑sh文件 vi test.sh(i:插入 | esc:退出insert模式 | wq+回车:退出) 3.保存退出 敲击esc, 然后输入 ...
- Java学习网站
黑马: http://bbs.itheima.com/forum.php 考试网站: http://www.nowcoder.com/ 牛客网 比较专业的学习技术网站: http://www.ibm. ...
- 如何检查失败的Segment/master
在启用Mirror情况下,可能出现Segment失败时,系统不会中断服务,而且没有明确提示.检查系统状态的一种方法就是使用gpstate命令.该命令会列出GPDB系统中每个独立组件(Primary I ...
- ORACLE--分区表数据清理
由于分区表数据增加:没做清除操作:导致表空间告急.需要清理很久之前的数据:释放空间.步骤如下 一,查看哪个表占的空间 SELECT t.segment_name, SUM(t.bytes / 1024 ...
- PMO究竟啥样?(3)
PMO究竟啥样?(3) 继续上一篇,PMO究竟啥样?到这篇,这篇文章就完毕啦. 超卓基地COE,4大典型责任 我们知道全部的公司,它都是要不断地继续改善和优化,包括公司内安排级的项目处理的机制,也需求 ...
- [HTML]DIV+CSS 文字垂直居中
在说到这个问题的时候,也许有人会问CSS中不是有vertical-align属性来设置垂直居中的吗?即使是某些浏览器不支持我只需做少许的CSS Hack技术就可以啊!所以在这里我还要啰嗦两句,CSS中 ...