http://acm.hdu.edu.cn/showproblem.php?pid=1595

这道题我用spfa在枚举删除边的时候求最短路超时,改用dijkstra就过了。

 #include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#define maxn 1001
using namespace std;
const int inf=<<; int g[maxn][maxn];
int n,m;
int s,e,c;
int dis[maxn];
bool vis[maxn];
int pre[maxn],pre1[maxn]; /*void spfa()
{
queue<int>q;
memset(vis,false,sizeof(vis));
for(int i=1; i<=n; i++) dis[i]=inf;
dis[1]=0;
vis[1]=true;
q.push(1);
pre[1]=-1;
while(!q.empty())
{
int u=q.front(); q.pop();
vis[u]=false;
for(int i=1; i<=n; i++)
{
if(dis[i]>dis[u]+g[u][i]&&g[u][i]!=inf)
{
dis[i]=dis[u]+g[u][i];
pre[i]=u;
if(!vis[i])
{
q.push(i);
vis[i]=true;
}
}
}
}
}*/ void dijstra()
{
memset(vis,false,sizeof(vis));
for(int i=; i<=n; i++) dis[i]=(i==?:inf);
for(int i=; i<=n; i++)
{
int x,mm=inf;
for(int y=; y<=n; y++) if(!vis[y]&&dis[y]<mm) mm=dis[x=y];
vis[x]=true;
for(int y=; y<=n; y++)
{
if(dis[y]>dis[x]+g[x][y]&&!vis[y])
{
pre[y]=x;
dis[y]=dis[x]+g[x][y];
}
}
}
}
void solve()
{
int v1=n;
pre1[]=-;
while(pre[v1]!=-)
{
pre1[v1]=pre[v1];
v1=pre[v1];
}
int v=n;
int max1=-;
while(pre1[v]!=-)
{
int mm=g[pre1[v]][v];
g[pre1[v]][v]=g[v][pre1[v]]=inf;
dijstra();
if(dis[n]!=inf)
max1=max(dis[n],max1);
g[pre1[v]][v]=g[v][pre1[v]]=mm;
v=pre1[v];
}
printf("%d\n",max1);
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(pre,-,sizeof(pre));
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(i==j) g[i][j]=;
else g[i][j]=inf;
}
}
for(int i=; i<m; i++)
{
scanf("%d%d%d",&s,&e,&c);
g[s][e]=g[e][s]=min(g[s][e],c);
}
dijstra();
solve();
}
return ;
}

hdu 1595 find the longest of the shortest的更多相关文章

  1. hdu 1595 find the longest of the shortest(迪杰斯特拉,减去一条边,求最大最短路)

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

  2. hdu 1595 find the longest of the shortest【最短路枚举删边求删除每条边后的最短路,并从这些最短路中找出最长的那条】

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

  3. hdu 1595 find the longest of the shortest(dijkstra)

    Problem Description Marica is very angry with Mirko because he found a new girlfriend and she seeks ...

  4. hdu 1595 find the longest of the shortest(dijstra + 枚举)

    http://acm.hdu.edu.cn/showproblem.php?pid=1595 大致题意: 给一个图.让输出从中删除随意一条边后所得最短路径中最长的. . 思路: 直接枚举每条边想必是不 ...

  5. HDU 1595 find the longest of the shortest【次短路】

    转载请注明出处:http://blog.csdn.net/a1dark 分析:经典的次短路问题.dijkstra或者SPFA都能做.先找出最短路.然后依次删掉没条边.为何正确就不证明了.了解思想直接A ...

  6. hdu1595 find the longest of the shortest(Dijkstra)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1595 find the longest of the shortest Time Limit: 100 ...

  7. find the longest of the shortest (hdu 1595 SPFA+枚举)

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

  8. hdu 1595(最短路变形好题)

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

  9. HDU 5373(2015多校7)-The shortest problem(模拟%11)

    题目地址:pid=5373">HDU 5373 题意:给你一个数n和操作次数t,每次操作将n的各位数之和求出来放在n的末尾形成新的n,问t次操作后得到的n能否够被11整除. 思路:就是 ...

随机推荐

  1. Cypress的开发板的UART接口打印调试信息

    说实话,在官方论坛现在还没有找到相关有用的消息,因为我们这个开发板的UART没引出来. http://www.cypress.com/?app=forum&id=167&rID=527 ...

  2. java开发经验分享(三)

    三. 项目开发 1. 需求: 1) 需求最终需要开发人员在产品中实现,开发不合理的设计会浪费时间,开发技术无法实现的设计带来最大的痛苦:失败.所以,开发人员要重视需求以及需求评审,提出自己能够想到的所 ...

  3. PHP关于时区问题

    最近在学习PHP过程中发现PHP中的格式化时间戳比北京时间晚了8个小时,上网搜索发现原来是时区不对,解决办法是:      1.永久修改           更改php.ini文件中的data.tim ...

  4. 第26讲 对话框AlertDialog的自定义实现

    第26讲对话框AlertDialog的自定义实现 比如我们在开发过长当中,要通过介绍系统发送的一个广播弹出一个dialog.但是dialog必需是基于activity才能呈现出来,如果没有activi ...

  5. jQuery----blur()方法

    当元素失去焦点时发生 blur 事件. blur() 函数触发 blur 事件,或者如果设置了 function 参数,该函数也可规定当发生 blur 事件时执行的代码. 提示:早前,blur 事件仅 ...

  6. Hive2.0函数大全(中文版)

    摘要 Hive内部提供了很多函数给开发者使用,包括数学函数,类型转换函数,条件函数,字符函数,聚合函数,表生成函数等等,这些函数都统称为内置函数. 目录 数学函数 集合函数 类型转换函数 日期函数 条 ...

  7. XAMPP安装及配置注意事项

    1.下载对应版本以后,解压安装 2.设置环境变量中的path,即D:\xampp\mysql\bin 3.设置监听端口 4.解决端口冲突问题 5.各种测试网址注意事项 由于很晚了,先记录下来,明天补充 ...

  8. mysql下用户和密码生成管理

    应用上线,涉及到用户名和密码管理,随着上线应用的增加,用户名和密码的管理设置成为一个问题.还要对用户赋权,于是想着写一个脚本来管理,看到同事写的一个脚本,满足需求.思路大致是字母替换为数字,账号根据库 ...

  9. Caused by: java.lang.ClassNotFoundException: javassist.ClassPool

    1.错误原因 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help ...

  10. hdu 1240 Asteroids! (三维bfs)

    Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...