一个水题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. [.net] c# webservice

    采用的工具VS2010生成工程 1. 生成webservice工程:建 ASP.NET 空WEB 应用程序. 2. 在建好的ASP.NET 空WEB应用程序中新建项“web 服务”. 完成上述内容工程 ...

  2. CodeForces 631D Messenger

    $KMP$. $n=1$和$n=2$的时候可以单独计算.$n>2$时,可以拿字符和数字分别做一次匹配,然后扫描一遍判断一下就可以计算出答案了. #pragma comment(linker, & ...

  3. USACO 4.1 Fence Loops(Floyd求最小环)

    Fence Loops The fences that surround Farmer Brown's collection of pastures have gotten out of contro ...

  4. yarn计算一个节点容量及其配置项

    mapred-site.xml mapreduce.map.memory.mb 1536 每个Map Container的大小 mapreduce.reduce.memory.mb 2560 每个Re ...

  5. HDU 1272 小希的迷宫(乱搞||并查集)

    小希的迷宫 Problem Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有 ...

  6. Hololens生成与安装(旁加载)应用

    Hololens生成应用的几种方式: 一:HoloToolkit编辑器生成appx应用 二:Vistul Studio 2015 创建应用 旁加载概述: 你可以将应用旁加载到你的设备,而无需将它们提交 ...

  7. Ubuntu14.04 bind9配置

    apt-get install bind9 配置域名: cn.archive.ubuntu.com 对应IP: 10.60.233.244 vim /etc/bind/name.conf.defaul ...

  8. Pass和ClassPath变量配置

    1.pass环境变量配置的是可执行性文件bin目录,是为了在任意盘符下都可以运行javac.exe和java.exe所配置的. 2.classpath环境变量记录的是java类运行文件所在的目录,一般 ...

  9. jmeter命令行运行-单节点

    jmeter有自己的GUI页面,但是当线程数很多或者现在有很多的测试场景都是基于linux下进行压测,这时我们可以使用jmeter的命令行方式来执行测试,该篇文章介绍jmeter单节点命令运行方式. ...

  10. mysql 数据库知识

    order by 字段    将查到的list集合按指定字段升序排序 order by 字段 DESC   将查到的list集合按指定字段降序排序 GROUP BY 语句用于结合合计函数,根据一个或多 ...