hdu 3986 Harry Potter and the Final Battle
一个水题WA了60发,数组没开大,这OJ也不提示RE,光提示WA。。。。。。
思路:先求出最短路,如果删除的边不是最短路上的,那么对结果没有影响,要有影响,只能删除最短路上的边。所以枚举一下最短路上的边,每次求最短路即可。
#include<stdio.h>
#include<vector>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std; const int maxn = + ;
const int INF = 0x7FFFFFFF;
int n, m, anss;
vector<int>ljb[maxn];
vector<int>bbb[maxn][maxn];
int jz[maxn][maxn];
int cost[ + ], flag[ + ], ff[maxn], dist[maxn];
int s[maxn], path[maxn]; void SPFA()
{
int i, ii;
queue<int>Q;
memset(ff, , sizeof(ff));
for (i = ; i <= n; i++) dist[i] = INF, s[i] = -;
ff[] = ; Q.push(); dist[] = ; s[] = ;
while (!Q.empty())
{
int h = Q.front(); Q.pop(); ff[h] = ;
for (i = ; i < ljb[h].size(); i++)
{
for (ii = ; ii < bbb[h][ljb[h][i]].size(); ii++)
{
if (flag[bbb[h][ljb[h][i]][ii]] ==)
{
if (dist[h] + cost[bbb[h][ljb[h][i]][ii]] < dist[ljb[h][i]])
{
dist[ljb[h][i]] = dist[h] + cost[bbb[h][ljb[h][i]][ii]];
s[ljb[h][i]] = h;
if (ff[ljb[h][i]] == )
{
ff[ljb[h][i]] = ;
Q.push(ljb[h][i]);
}
}
}
}
}
}
} int main()
{
int sb;
scanf("%d", &sb);
while (sb--)
{
int i, j, u, v;
scanf("%d%d", &n, &m);
memset(flag, , sizeof(flag));
for (i = ; i <= n; i++) for (j = ; j <= n; j++) jz[i][j] = INF;
for (i = ; i <= n; i++) for (j = ; j <= n; j++) bbb[i][j].clear();
for (i = ; i <= n; i++) ljb[i].clear();
for (i = ; i <= m; i++)
{
scanf("%d%d%d", &u, &v, &cost[i]);
if (jz[u][v] == INF) jz[u][v] = i, jz[v][u] = i;
if (cost[i] < cost[jz[u][v]]) jz[u][v] = i, jz[v][u] = i;
bbb[u][v].push_back(i);
bbb[v][u].push_back(i);
ljb[u].push_back(v);
ljb[v].push_back(u);
}
SPFA();
anss = -;
if (dist[n] != INF)
{
path[] = n; int q = ;
while ()
{
path[q] = s[path[q - ]];
if (path[q] == ) break;
q++;
}
for (i = ; i <= q - ; i++)
{
flag[jz[path[i]][path[i + ]]] = ;
SPFA();
if (dist[n] == INF){ anss = -; break; }
if (dist[n] > anss) anss = dist[n];
flag[jz[path[i]][path[i + ]]] = ;
}
}
printf("%d\n", anss);
}
return ;
}
hdu 3986 Harry Potter and the Final Battle的更多相关文章
- 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 ...
- 【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 ...
- hdu3986Harry Potter and the Final Battle
给你一个无向图,然后找出当中的最短路, 除去最短路中的随意一条边,看最糟糕的情况下, 新的图中,第一个点到末点的最短路长度是多少. 我的做法是: 首先找出最短路,然后记录路径, 再一条一条边的删, 删 ...
- hdu 3986(最短路变形好题)
Harry Potter and the Final Battle Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/6553 ...
- HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)
Harry Potter and the Hide Story Problem Description iSea is tired of writing the story of Harry Pott ...
- HDU 3986
http://acm.hdu.edu.cn/showproblem.php?pid=3986 从开始的最短路里依次删一条边,求新的最短路,求最长的最短路 删边操作要标记节点以及节点对应的边 #incl ...
- HDU 3987 Harry Potter and the Forbidden Forest(边权放大法+最小割)
Harry Potter and the Forbidden Forest Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/ ...
- hdu 3987 Harry Potter and the Forbidden Forest 求割边最少的最小割
view code//hdu 3987 #include <iostream> #include <cstdio> #include <algorithm> #in ...
- Bridges: The Final Battle
对修改操作按时间分治,设$solve(l,r,n,m)$为考虑时间在$[l,r]$的修改操作,作用范围是$n$个点,$m$条边的图. 若$l=r$,则暴力Tarjan统计桥边个数即可. 否则提取出$[ ...
随机推荐
- webpack入门必知必会
关于 微信公众号:前端呼啦圈(Love-FED) 我的博客:劳卜的博客 知乎专栏:前端呼啦圈 前言 这是我第一篇介绍webpack的文章,先从一个入门教程开始吧,后续会有更多相关webpack的文章推 ...
- [ios2]警告:Block的Retain Cycle的解决方法 【转】
<span style="background-color: rgb(248, 248, 248); font-family: 'PT Sans', Geogia, Baskervil ...
- C++11多线程std::thread的简单使用
在cocos2dx 2.0时代,我们使用的是pthread库,是一套用户级线程库,被广泛地使用在跨平台应用上.但在cocos2dx 3.0中并未发现有pthread的支持文件,原来c++11中已经拥有 ...
- iOS开发-OC语言 (七)继承、多态、类别
继承.多态.类别 学习目标 1.继承的含义 2.父类子类的别称 3.字段和消息的继承 4.重写和重写消息的调用 5.多态 6.类别(Category) ======================== ...
- React一些必须要知道的基础
React 起源于 Facebook 的内部项目,因为该公司对市场上所有 JavaScript MVC 框架,都不满意,就决定自己写一套,用来架设 Instagram 的网站.做出来以后,发现这套东西 ...
- SDN理解:云数据中心底层网络架构
目录 - 目录 - 云数据中心流量类型 - NSX整体网络结构 - 管理网络(API网络) - 租户网络 - 外联网络 - 存储网络 - openstack整体网络结构 - 管理网络:(上图中蓝线) ...
- TypeScript -- 面向对象特性
.class关键字和类名就可以定义一个类 . 类的访问控制符--有三个,.] = ] = ] = ;.声明参数 .用接口声明方法 .理解模块--一个文件就是一个模块,就是这么个意思 ,不用想的多么高大 ...
- Leetcode-34-Search Insert Position-(Medium)
二分法查找需要插入的位置,需要注意两点 1.如果元素不存在,停止的时候start Index刚好是需要插入的位置 2.如果元素存在,需要向前追溯找到非目标元素的起始边界 #!/usr/local/bi ...
- 跨线程传递栈变量带来异常指针Crash
在手Q动漫的一份古老的代码中,现网发现少数crash,错误代码示例: char str[100] = "hello"; dispatch_async(dispatch_get_ma ...
- Linux双网卡NAT共享上网
linux双网卡NAT共享上网 术语字汇 私有IP地址(路由不可达地址)是一个被用于本地局域网的IP地址(在互联网中不可见). 公用IP地址(路由可达地址)是一个在互联网中可见的IP地址. IP伪装是 ...