一个水题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的更多相关文章

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

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

  3. hdu3986Harry Potter and the Final Battle

    给你一个无向图,然后找出当中的最短路, 除去最短路中的随意一条边,看最糟糕的情况下, 新的图中,第一个点到末点的最短路长度是多少. 我的做法是: 首先找出最短路,然后记录路径, 再一条一条边的删, 删 ...

  4. hdu 3986(最短路变形好题)

    Harry Potter and the Final Battle Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65536/6553 ...

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

  6. HDU 3986

    http://acm.hdu.edu.cn/showproblem.php?pid=3986 从开始的最短路里依次删一条边,求新的最短路,求最长的最短路 删边操作要标记节点以及节点对应的边 #incl ...

  7. HDU 3987 Harry Potter and the Forbidden Forest(边权放大法+最小割)

    Harry Potter and the Forbidden Forest Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65536/ ...

  8. hdu 3987 Harry Potter and the Forbidden Forest 求割边最少的最小割

    view code//hdu 3987 #include <iostream> #include <cstdio> #include <algorithm> #in ...

  9. Bridges: The Final Battle

    对修改操作按时间分治,设$solve(l,r,n,m)$为考虑时间在$[l,r]$的修改操作,作用范围是$n$个点,$m$条边的图. 若$l=r$,则暴力Tarjan统计桥边个数即可. 否则提取出$[ ...

随机推荐

  1. 在Node.js中使用RabbitMQ系列一 Hello world

    在前一篇文章中可伸缩架构简短系列中提到过关于异步的问题.当时推荐使用RabbitMQ来做任务队列的实现方案.本篇文章以Node.js为例子,来实际操作如何和RabbitMQ进行交互. 介绍 Rabbi ...

  2. Node.js学习笔记(二):模块

    模块是 Node.js 应用程序的基本组成部分,文件和模块是一一对应的.一个 Node.js 文件就是一个模块,这个文件可能是 JavaScript 代码.JSON 或者编译过的 C/C++ 扩展. ...

  3. canvas 弹幕效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Docker集群实验环境布署--swarm【7 让docker客户端支持docker-compose】

    Docker-Compose是一个部署多个容器的简单但是非常必要的工具.   登录Docker客户端的服务器(默认是安装了docker-engine的服务器),再安装compose插件 # yum i ...

  5. 使用spring-data-mongodb操作mongodb

    mongodb.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="h ...

  6. springmvc中返回页面,只在iframe中跳转,而不是整个页面,解决方法。

    问题描述:在我写的主页面中用到了iframe,其中在iframe中有一个button点击提交,然后在Controller中返回页面的时候,是在iframe中打开的,而不是整个页面. 最开始我想用aja ...

  7. WPF 后台绑定样式

    private ContentControl cc = null; private void muiscPlay(object sender, RoutedEventArgs e) { string ...

  8. Ubuntu 16 04 安装KVM

    apt-get install qemu-kvm ubuntu-vm-builder bridge-utils http://www.linuxidc.com/Linux/2016-06/132188 ...

  9. Thinkphp5 设置日志

    database.php 'debug' => false, application/config.php 'log' => [ // 日志记录方式,支持 file socket 'typ ...

  10. MariaDB数据解压版安装(10.0.16)

    官网下载地址:https://downloads.mariadb.org/    (自己选择版本下载) 在windows 7 下安装 1.下载到解压版安装文件mariadb-10.0.16-win32 ...