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): 3198 Accepted Submission(s): 1249
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.
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= ;
const double eps= 1e-;
const int inf = 0x3f3f3f3f;
const int mod =;
typedef long long ll;
typedef long double ld;
int n,m;
int dp[maxn][maxn];
int ma[maxn][maxn];
int main()
{
while(scanf("%d %d",&n,&m)!=EOF&&n&&m)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(i==j)
ma[i][j]=;
else
ma[i][j]=inf;
}
}
int x,y,d;
for(int i=;i<m;i++)
{
scanf("%d %d %d",&x,&y,&d);
ma[x][y]=ma[y][x]=d;
}
int ans=-inf;
for(int l=;l<=n-;l++)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(i==l||j==l)
dp[i][j]=inf;
else
dp[i][j]=ma[i][j];
}
}
dp[l][l]=;
for(int k=;k<=n;k++)
{
for(int i=;i<=n;i++)
{
if(dp[i][k]!=inf)
for(int j=;j<=n;j++)
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
}
}
ans=max(ans,dp[][n]);
}
if(ans==inf)
printf("Inf\n");
else
printf("%d\n",ans);
}
}
HDU5137 删点 最短路的更多相关文章
- P1186 玛丽卡 删边最短路最大值
反正蛮水的一道题. 胡雨菲一句话让我的代码减少了10行还A了,之前的是个错的. 思路:先求出最短路,然后依次删去最短路上的每一条边,跑最短路求最大值. 关于删边:我的想法是当作链表删除,把last的n ...
- Codeforces 1163F 最短路 + 线段树 (删边最短路)
题意:给你一张无向图,有若干次操作,每次操作会修改一条边的边权,每次修改后输出1到n的最短路.修改相互独立. 思路:我们先以起点和终点为根,找出最短路径树,现在有两种情况: 1:修改的边不是1到n的最 ...
- 【转】最短路&差分约束题集
转自: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)★ ...
- 最短路&查分约束
[HDU] 1548 A strange lift 根蒂根基最短路(或bfs)★ 2544 最短路 根蒂根基最短路★ 3790 最短路径题目 根蒂根基最短路★ 2066 一小我的观光 根蒂根基最短路( ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- ACdream 1083 有向无环图dp
题目链接:点击打开链接 人民城管爱人民 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Othe ...
- 【HDOJ图论题集】【转】
=============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
随机推荐
- IOS学习8——常用框架学习汇总
我们在学习和code过程中经常会用到一些框架,本文将会持续更新最新学习和用到的框架 布局框架: Masonry介绍与使用实践:快速上手Autolayout iOS MJRefresh下拉.上拉刷新自定 ...
- 用keras作CNN卷积网络书本分类(书本、非书本)
本文介绍如何使用keras作图片分类(2分类与多分类,其实就一个参数的区别...呵呵) 先来看看解决的问题:从一堆图片中分出是不是书本,也就是最终给图片标签上:“书本“.“非书本”,简单吧. 先来看看 ...
- 谈谈CommonsChunkPlugin抽取公共模块
引言 webpack插件CommonsChunkPlugin的主要作用是抽取webpack项目入口chunk的公共部分,具体的用法就不做过多介绍,不太了解可以参考webpack官网介绍: 该插件是we ...
- SpringMVC 返回json的两种方式
前后台数据交互使用json是一种很重要的方式.本文主要探讨SpringMVC框架使用json传输的技术. 请注意,本文所提到的项目使用Spring 版本是4.1.7,其他版本在具体使用上可能有不一样的 ...
- CET-4- translation1
questions 2017/10/17 多年来,家长和老手都曾得到过这样一种信息(message):尽量利用任何机会表扬孩子,对他们所干的任何事情都要说好.据说这样做有助于提高孩子的自尊.但是近来许 ...
- Git常用命令清单笔记
git github 小弟调调 2015年01月12日发布 赞 | 6收藏 | 45 5k 次浏览 这里是我的笔记,记录一些git常用和一些记不住的命令,这个笔记原本是基于 颜海镜的文章增加 ...
- alias 命令详解
alias 命令 作用: 设置命令别名,可以将较长的命令进行简化,使用alias 时,用户必须使用单引号将原来的命令引起来,防止特殊字符导致错误. 如要永久生效则将alias 命令存放到bash 的 ...
- input上传图片(file),预览图片的两种方法。blob与base64编码
上传图片时一般都需要预览,我一般用这两种方法来实现.base64编码可以直接上传到后台,后台解析下,得到的文件就会比较小了,省去了压缩图片这一步了. //获取对象input file 的图片地址,放进 ...
- POI 导出导入工具类介绍
介绍: Apache POI是Apache软件基金会的开源项目,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. .NET的开发人员则可以利用NPOI (POI ...
- 房上的猫:switch选择结构,与选择结构总结
switch选择结构: 一.定义: switch选择结构,可以方便地解决等值判断问题二.语法: switch(表达式){ case 常量1: //代码块1; break; c ...