How Many Maos Does the Guanxi Worth

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 760    Accepted Submission(s): 290

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
Sample Output
 50
 Inf
题意:1到n个人,在删除一个人(除第1个人和第n个人外)情况下,求打通关系从第一个1到第n人所花费最多的钱。
思路:枚举+dijkstra
收获:dijkstra应用。dijkstra:求单源最短路径,边权要为正。
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
using namespace std; const int INF=0x3f3f3f3f;
const double eps=1e-;
const double PI=acos(-1.0); const int maxn=;
int w[maxn][maxn];
int n, m;
int v[maxn];
int d[maxn];
int num[maxn];
int dijkstra(int k)
{
memset(v, , sizeof(v));
v[k] = ;
for(int i = ; i <= n; i++) d[i] = (i== ? : INF);
for(int i = ; i <= n; i++)
{
int x, m = INF;
for(int j = ; j <= n; j++) if(!v[j] && d[j]<=m) m = d[x=j];
v[x]=;
for(int j = ; j <= n; j++) d[j] = min(d[j], d[x] + w[x][j]);
}
return d[n];
}
int main()
{
while(~scanf("%d%d", &n, &m))
{
if(n== && m==)
break;
memset(w, INF, sizeof(w));
int a, b, t;
for(int i = ; i < m; i++)
{
scanf("%d%d%d", &a, &b, &t);
w[a][b] = w[b][a] = min(t, w[a][b]);
}
//int ans = INF;
int cnt = ;
memset(num, INF, sizeof(num));
for(int i = ; i < n; i++) cnt = max(cnt, dijkstra(i));
if(cnt == INF)
printf("Inf\n");
else
printf("%d\n", cnt);
}
return ;
}

HDU5137 How Many Maos Does the Guanxi Worth(枚举+dijkstra)的更多相关文章

  1. 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 ...

  2. hdu5137 How Many Maos Does the Guanxi Worth(单源最短路径)

    题目链接:pid=5137">点击打开链接 题目描写叙述:如今有一张关系网.网中有n个结点标号为1-n.有m个关系,每一个关系之间有一个权值.问从2-n-1中随意去掉一个结点之后,从1 ...

  3. 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/5 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. (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 ...

  9. 杭电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 ...

随机推荐

  1. 最详细的 HTTPS 科普扫盲帖

    为什么需要https HTTP是明文传输的,也就意味着,介于发送端.接收端中间的任意节点都可以知道你们传输的内容是什么.这些节点可能是路由器.代理等. 举个最常见的例子,用户登陆.用户输入账号,密码, ...

  2. [Linux] killall 、kill 、pkill 命令详解

    killall 命令 Linux系统中的killall命令用于杀死指定名字的进程(kill processes by name).我们可以使用kill命令杀死指定进程PID的进程,如果要找到我们需要杀 ...

  3. 04747_Java语言程序设计(一)_第3章_面向对象编程基础

    链式编程 每次调用方法后,返回的是一个对象 /* * 链式编程 * 每次调用方法后,返回的是一个对象 */ class Student { public void study() { System.o ...

  4. SpringMVC学习系列- 表单验证

    本篇我们来学习Spring MVC表单标签的使用,借助于Spring MVC提供的表单标签可以让我们在视图上展示WebModel中的数据更加轻松. 一.首先我们先做一个简单了例子来对Spring MV ...

  5. [重磅] 让HTML5达到原生的体验 系列之中的一个 避免切页白屏

    非常多人都想.甚至曾使用HTML5开发跨平台App.而且想达到原生App的体验. 最后的结果都是无奈的放弃.HTML5貌似美好,但坑太多.想做到原生App的体验差点儿不可为. 也曾有过著名的faceb ...

  6. 利用boost获取时间并格式化

    利用boost来获取当前时间又方便快捷,还不用考虑跨平台的问题. 1. 输出YYYYMMDD #include <boost/date_time/gregorian/gregorian.hpp& ...

  7. flexible.js字体大小诡异现象解析及解决方案

    最近在做一个手机端页面时,遇到了一个奇怪的问题:字体的显示大小,与在CSS中指定的大小不一致.大家可以查看这个Demo(记得打开Chrome DevTools). 就如上图所示,你可以发现,原本指定的 ...

  8. C++服务器设计(五):多设备类型及消息事件管理

    在传统的服务器系统中,服务器仅针对接收到的客户端消息进行解析,并处理后回复响应.在该过程中服务器并不会主动判断客户端类型.但在现实中,往往存在多种类型的客户端设备,比如物联网下的智能家居系统,就存在智 ...

  9. poj2774 Long Long Message(后缀数组or后缀自动机)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Long Long Message Time Limit: 4000MS   Me ...

  10. 【HTML5】在head 设置 meta 能更方便开发

    <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initi ...