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 ...
随机推荐
- 元类 metaclass
metaclass 类由Type创建 对象由创建 MetaClass作用 用来指定当前类由谁来创建(默认type创建). MetaClass 会被继承,如果父类指定了元类,那么子类也是由这个元类创建 ...
- POJ - 2125 Destroying The Graph (最小点权覆盖)
题意:给一张图,现在要删去所有的边,删去一个点的所有入边和所有出边都有其对应\(W_{i+}\)和\(W_{i-}\).求删去该图的最小花费,并输出解 分析:简而言之就是用最小权值的点集去覆盖所有的边 ...
- CDH5离线安装简记
需要的介质如下:CM: cloudera-manager-el6-cm5.4.3_x86_64.tar.gzCDH parcel: CDH-5.4.0-1.cdh5.4.0.p0.27-el6.par ...
- 【android】夜间模式简单实现
完整代码,请参考我的博客园客户端,git地址:http://git.oschina.net/yso/CNBlogs 关于阅读类的app,有个夜间模式真是太重要了. 那么有两种方式可以实现夜间模式 1: ...
- manager
S 识别 M 买账 A-安排 R-认同 T-提问识别上级的沟通特点,判断形势,识别沟通的时机摆正自己的角色位置,礼多人不怪,回应情绪做好沟通准备,有策略,安排合适时间听取反馈意见,认同并接纳指导提问 ...
- 如何用纯 CSS 创作一个变色旋转动画
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/ejZWKL 可交互视频 ...
- 在linux环境下安装python3.6
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz --no-check-certificat gunzip Python-3. ...
- spring boot加mybatis使用Map返回时,当值为空时属性也会没有(转)
使用spring boot加mybatis时,设置Map返回,当值为空时属性也会没有,就会报错 在application.properties中加入下面配置,将会解决这个问题. #当查询数据为空时 ...
- HTTP-java访问https资源时,忽略证书信任问题,代码栗子
java程序在访问https资源时,出现报错 sun.security.validator.ValidatorException: PKIX path building failed: sun.sec ...
- zsh + oh-my-zsh 主题预览
The Themes robbyrussell the (default) that Robby uses The rest of the themes, in alphabetical order: ...