HDU 3986
http://acm.hdu.edu.cn/showproblem.php?pid=3986
从开始的最短路里依次删一条边,求新的最短路,求最长的最短路
删边操作要标记节点以及节点对应的边
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std ;
const int INF=0xfffffff ;
struct node{
int s,t,v,nxt ;
}e[] ;
int n,m,cnt,dis[],vis[],head[],fa[],pre[],flag,mk[] ;
int add(int s,int t,int v)
{
e[cnt].s=s ;
e[cnt].t=t ;
e[cnt].v=v ;
e[cnt].nxt=head[s] ;
head[s]=cnt++ ;
}
void spfa()
{
for(int i= ;i<=n ;i++)
dis[i]=INF ;
memset(vis,,sizeof(vis)) ;
dis[]= ;
vis[]= ;
queue <int> q ;
q.push() ;
while(!q.empty())
{
int u=q.front() ;
q.pop() ;
vis[u]= ;
for(int i=head[u] ;i!=- ;i=e[i].nxt)
{
int tt=e[i].t ;
if(!flag && mk[tt] && (pre[tt]==i || pre[tt]==i+))continue ;
if(dis[tt]>e[i].v+dis[u])
{
dis[tt]=e[i].v+dis[u] ;
if(flag)
{
fa[tt]=u ;
pre[tt]=i ;
}
if(!vis[tt])
{
vis[tt]= ;
q.push(tt) ;
}
}
}
}
}
int main()
{
int t ;
scanf("%d",&t) ;
while(t--)
{
scanf("%d%d",&n,&m) ;
cnt= ;
memset(head,-,sizeof(head)) ;
memset(mk,,sizeof(mk)) ;
for(int i= ;i<m ;i++)
{
int s,t,v ;
scanf("%d%d%d",&s,&t,&v) ;
add(s,t,v) ;add(t,s,v) ;
}
flag= ;
spfa() ;
flag= ;
int ans= ;
for(int i=n ;i!= ;i=fa[i])
{
mk[i]= ;
spfa() ;
if(dis[n]==INF)
{
ans=- ;
break ;
}
ans=max(ans,dis[n]) ;
mk[i]= ;
}
printf("%d\n",ans) ;
}
return ;
}
HDU 3986的更多相关文章
- 【Dijstra堆优化】HDU 3986 Harry Potter and the Final Battle
http://acm.hdu.edu.cn/showproblem.php?pid=3986 [题意] 给定一个有重边的无向图,T=20,n<=1000,m<=5000 删去一条边,使得1 ...
- hdu 3986 Harry Potter and the Final Battle
一个水题WA了60发,数组没开大,这OJ也不提示RE,光提示WA...... 思路:先求出最短路,如果删除的边不是最短路上的,那么对结果没有影响,要有影响,只能删除最短路上的边.所以枚举一下最短路上的 ...
- hdu 3986 Harry Potter and the Final Battle (最短路径)
Harry Potter and the Final Battle Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/6553 ...
- hdu 3986(最短路变形好题)
Harry Potter and the Final Battle Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/6553 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
随机推荐
- Visual Studio Code常用设置
Visual Studio Code常用设置 • 自动保存设置 ▶ 文件(F) -> 首选项(P) -> 用户设置(U) ▶ 将"files.autoSave": &q ...
- python16_day39【算法】
复习: 1.递归 调用自身 结束条件 一.冒泡算法 def bubble_sort(numbs): for i in range(len(numbs)-1): # 这个循环负责设置冒泡排序进行的次数. ...
- Linux系统——公网定制化yum仓库部署
1)搭建公网源yum仓库 安装wget aliyun源 # wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel ...
- SpringData_Repository接口概述
Repository 接口是 Spring Data 的一个核心接口,它不提供任何方法,开发者需要在自己定义的接口中声明需要的方法 public interface Repository<T, ...
- Thymeleaf使用说明
Thymeleaf使用说明 javascript操作: a.<script type="text/javascript" th:inline="javascript ...
- ACM ICPC, Damascus University Collegiate Programming Contest(2018) Solution
A:Martadella Stikes Again 水. #include <bits/stdc++.h> using namespace std; #define ll long lon ...
- python weekday()函数
def weekday(self): """Return the day of the week as an integer, where Monday is 0 and ...
- Qt信号和槽连接方式的选择
看了下Qt的帮助文档,发现connect函数最后还有一个缺省参数. connect函数原型是这样的: QMetaObject::Connection QObject::connect(const QO ...
- Vue学习笔记之Webpack介绍
在这里我仅仅的是对webpack做个讲解,webpack这个工具非常强大,解决了我们前端很繁琐的一些工具流程繁琐的事情.如果感兴趣的同学,简易还是看官网吧. 中文链接地址:https://www.we ...
- 20145221 《Java程序设计》第七周学习总结
20145221 <Java程序设计>第七周学习总结 教材学习内容总结 第十二章部分 - Lambda 认识Lambda语法 Lambda去可以重复,符合DRY原则,而且Lambda表达式 ...