tag是假的,用了及其诡异的方法判负环

正权无向边和负权有向边的图

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=505,inf=210000000;
int n,m,w,h[N],cnt,d[N];
struct qwe
{
int ne,to,va;
}e[N*N];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
void add(int u,int v,int w)
{
cnt++;
e[cnt].ne=h[u];
e[cnt].to=v;
e[cnt].va=w;
h[u]=cnt;
}
bool ok()
{
for(int i=1;i<=n;i++)
d[i]=inf;
d[1]=0;
for(int i=1;i<n;i++)
for(int j=1;j<=n;j++)
for(int k=h[j];k;k=e[k].ne)
if(d[e[k].to]>e[k].va+d[j])
d[e[k].to]=e[k].va+d[j];
for(int i=1;i<=n;i++)
for(int j=h[i];j;j=e[j].ne)
if(d[e[j].to]>d[i]+e[j].va)
return 1;
return 0;
}
int main()
{
int T=read();
while(T--)
{
memset(h,0,sizeof(h));
cnt=0;
n=read(),m=read(),w=read();
for(int i=1;i<=m;i++)
{
int x=read(),y=read(),z=read();
add(x,y,z),add(y,x,z);
}
for(int i=1;i<=w;i++)
{
int x=read(),y=read(),z=read();
add(x,y,-z);
}
if(ok())
puts("YES");
else
puts("NO");
}
return 0;
}

bzoj 1715: [Usaco2006 Dec]Wormholes 虫洞【spfa判负环】的更多相关文章

  1. bzoj 1715: [Usaco2006 Dec]Wormholes 虫洞 -- spfa判断负环

    1715: [Usaco2006 Dec]Wormholes 虫洞 Time Limit: 5 Sec  Memory Limit: 64 MB 注意第一次加边是双向边第二次是单向边,并且每次询问前数 ...

  2. BZOJ 1715: [Usaco2006 Dec]Wormholes 虫洞 DFS版SPFA判负环

    Description John在他的农场中闲逛时发现了许多虫洞.虫洞可以看作一条十分奇特的有向边,并可以使你返回到过去的一个时刻(相对你进入虫洞之前).John的每个农场有M条小路(无向边)连接着N ...

  3. BZOJ 1715: [Usaco2006 Dec]Wormholes 虫洞

    Description John在他的农场中闲逛时发现了许多虫洞.虫洞可以看作一条十分奇特的有向边,并可以使你返回到过去的一个时刻(相对你进入虫洞之前).John的每个农场有M条小路(无向边)连接着N ...

  4. 1715: [Usaco2006 Dec]Wormholes 虫洞

    1715: [Usaco2006 Dec]Wormholes 虫洞 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 501  Solved: 278[Sub ...

  5. Poj 3259 Wormholes(spfa判负环)

    Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 42366 Accepted: 15560 传送门 Descr ...

  6. POJ3259 Wormholes 【spfa判负环】

    题目链接:http://poj.org/problem?id=3259 Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submis ...

  7. POJ3259:Wormholes(spfa判负环)

    Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 68097   Accepted: 25374 题目链接: ...

  8. UVA 558 Wormholes 【SPFA 判负环】

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  9. Wormholes(spfa判负环)

      POJ - 3259—— Wormholes Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & % ...

随机推荐

  1. Linux清除arp缓存

    arp缓存就是IP地址和MAC地址关系缓存列表.在Windows下 arp -d [$ip] 不指定IP地址时清除所有arp缓存.在Linux下 arp -d $ip 必须指定IP地址才能执行这条命令 ...

  2. 解决Android Studio2.0不能使用HttpClient

    在build.gradle中的android {}中加上useLibrary 'org.apache.http.legacy'

  3. hdu_1085_Holding Bin-Laden Captive!_201404261008

    Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  4. Kerberos认证浅析

    1 引言 在希腊神话中Kerberos是守护地狱之门的一条凶猛的三头神犬,而我们在本文中所要介绍的Kerberos认证协议是由美国麻省理工学院(MIT)首先提出并实现的,是该校雅典娜计划的一部分.这个 ...

  5. Java日期LocalDate使用

    在做报表统计时,需要对指定时间内的数据做统计,则需要使用到时间日期API 在此使用的是java.util.Date的完美私生子LocalDate类 LocalDate方法介绍 now() : 从默认时 ...

  6. 当遇到Mac的Excel或者Word老是重复崩溃的时候

    打开Number,新建文件然后导出为Excel.之后再用Excel打开,一切都OK了.

  7. java MAT 分析

    java MAT 分析 http://blog.csdn.net/qeqeqe236/article/details/43577857 https://www.cnblogs.com/AloneSwo ...

  8. centos7更新、更新、每天更新、每天自动更新

    每一天我们的系统时时刻刻都被凶狠之徒盯着,保持软件在最新的状态是其中一项我们必须做,也很容易做到的工作. 首先我们立即手动更新所有预先安装的软件: yum -y update 跟着设定系统定时自动更新 ...

  9. [Spring Boot ] Creating the Spring Boot Project : Demo: Creating a REST Controller

    In Spring boot, define a REST API endpoint is pretty easy. package com.globomatisc.bike.controllers; ...

  10. 百度知道的代码复制粘贴到VB没有换行怎么办

    在如下所示的网页中,复制 粘贴到word文档,换行还是有的   再复制到VB6.0中还是可用的