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

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.

 
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.

 
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 5
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
      可以选择删掉图中的一个点后使得最短路尽可能的大,点数很少,枚举所有点依次删除,然后跑n-2次最短路就好了。

 #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 ;
}
Sample Output
50
Inf
 

HDU5137-最短路-删点的更多相关文章

  1. HDU1595-最短路-删边

    find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  2. Codeforces Round #302 (Div. 2) D. Destroying Roads 最短路 删边

    题目:有n个城镇,m条边权为1的双向边让你破坏最多的道路,使得从s1到t1,从s2到t2的距离分别不超过d1和d2. #include <iostream> #include <cs ...

  3. 【转】最短路&差分约束题集

    转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...

  4. 转载 - 最短路&差分约束题集

    出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548    A strange lift基础最短路(或bfs)★ ...

  5. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  6. SGU185 - Two Shortest

    原题地址:http://acm.sgu.ru/problem.php?contest=0&problem=185 题目大意:给出一个无向图,求出从 1 到 n 的两条没有相同边的最短路径(允许 ...

  7. NOIP算法总结

    前言 离NOIP还有一个星期,匆忙的把寒假整理的算法补充完善,看着当时的整理觉得那时还年少.第二页贴了几张从贴吧里找来的图片,看着就很热血的.旁边的同学都劝我不要再放PASCAL啊什么的了,毕竟我们的 ...

  8. 冲刺NOIP复习,算法知识点总结

    前言        离NOIP还有一个星期,匆忙的把整理的算法补充完善,看着当时的整理觉得那时还年少.第二页贴了几张从贴吧里找来的图片,看着就很热血的.当年来学这个竞赛就是为了兴趣,感受计算机之美的. ...

  9. 【HDOJ图论题集】【转】

    =============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...

随机推荐

  1. 细说PHP7

    PHP7带来的新东西 1.类型的声明. 可以使用字符串(string), 整数 (int), 浮点数 (float), 以及布尔值 (bool),来声明函数的参数类型与函数返回值. declare(s ...

  2. matplotlib绘制等高线图

    参考自Matplotlib Python 画图教程 (莫烦Python)(12)_演讲•公开课_科技_bilibili_哔哩哔哩 https://www.bilibili.com/video/av16 ...

  3. 工作笔记——js前端规范

    去年年末做了一个项目,因为第一次做前端管理职位,第一次做整个项目的前端架构很多东西都不熟悉,作为一次大胆的尝试. js方面的只有一个坑,那就是前端与后端的网络层封装,这一块是在后端的协助下开发的.网络 ...

  4. JavaScript:学习笔记(8)——对象扩展运算符

    JavaScript:学习笔记(8)——扩展运算符 对象的扩展运算符 扩展运算符是三个点(...).用于取出参数对象的所有可遍历属性,然后拷贝到当前对象之中. 如上图所示,新建了一个对象a,然后通过扩 ...

  5. 斐讯面试记录—三线程交替打印ABC

    package cn.shenzhen.feixun; public class PrintABC extends Thread{ private String name; private Objec ...

  6. zookeeper 监听事件 PathChildrenCacheListener

    zookeeper 监听事件 PathChildrenCacheListener PathChildrenCacheListener一次父节点注册,监听每次子节点操作,不监听自身和查询. 1.测试类: ...

  7. C++之条形码,windows下zint库的编译及应用(一)

    zint库是一个开源的第三方库,提供了生成条形码.二维码等功能.本文主要介绍zint库的生成及简单应用. 工具/原料   vs2012 代码文件下载   1 下载zint包 2 zint依赖另外两个库 ...

  8. 浅析SQL注入

    body, td { font-family: calibri; font-size: 10pt; } 演示 记得以前瞎鼓捣的时候,学过一个传说中的SQL注入万能字符串,是这个样子的' or '1'= ...

  9. 【Head First Servlets and JSP】笔记 27: web 应用安全

    典型的安全问题:假冒者.窃听者.非法升级者 认证方式: Base64 .摘要认证 .客户端证书.表单认证,重点熟悉摘要算法( HASH . MD5 等) 安全机制:授权.认证.数据完整性.机密性 80 ...

  10. 前端js实现字符串/图片/excel文件下载

    在web开发中,如果你想让用户下载或者导出一个文件,应该怎么做呢?传统的做法是在后端存储或者即时生成一个文件来提供下载功能,这样的优势是可以做权限控制.数据二次处理,但缺点是需要额外发起请求.增大服务 ...