死活调不出来

后来是发现这题建边的原因……

吐血.jpg

所谓的虫洞传说也就是负边了

然后这里打的spfa和原来的不一样

感觉hzwer大佬的spfa好强啊……

也更易写一点

贴代码

#include<bits/stdc++.h>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define ll long long
#define N 100005
#define INF 2147483647
using namespace std;
inline int read() {
int f = , x = ; char ch;
do { ch = getchar(); if (ch == '-')f = -; } while (ch<'' || ch>'');
do { x = x * + ch - ''; ch = getchar(); } while (ch >= ''&&ch <= '');
return f * x;
}
bool flag;
int n,m,w,cnt;
int head[],dis[];
bool mark[];
struct data{
int to,next,v;
}e[];
void add(int u,int v,int w)
{
e[++cnt].to=v;e[cnt].next=head[u];head[u]=cnt;e[cnt].v=w;
}
void spfa(int x)
{
mark[x]=;
for(int i=head[x];i;i=e[i].next)
if(e[i].v+dis[x]<dis[e[i].to])
{
if(mark[e[i].to]){flag=;return;}
else
{
dis[e[i].to]=e[i].v+dis[x];
spfa(e[i].to);
}
}
mark[x]=;
}
bool check()
{
for(int i=;i<=n;i++){
dis[i]=INF;
mark[i]=;
}
flag=;
for(int i=;i<=n;i++)
{
dis[i]=;
spfa(i);
if(flag) return ;
}
return ;
}
int main()
{
int F=read();
while(F--)
{
cnt=;
n=read(),m=read(),w=read();
memset(head,,sizeof(head));
for(int i=;i<=m;i++)
{
int s=read(),e=read(),t=read();
add(s,e,t);
add(e,s,t);
}
for(int i=;i<=w;i++)
{
int s=read(),e=read(),t=read();
add(s,e,-t);
}
if(check()) puts("YES");
else puts("NO");
}
return ;
}

[P2850][USACO06DEC]虫洞Wormholes (最短路)的更多相关文章

  1. 洛谷 P2850 [USACO06DEC]虫洞Wormholes 题解

    P2850 [USACO06DEC]虫洞Wormholes 题目描述 While exploring his many farms, Farmer John has discovered a numb ...

  2. 洛谷 P2850 [USACO06DEC]虫洞Wormholes 判负环

    虫洞(wormhole) FJ 在农场上闲逛时,发现他的农场里有很多虫洞.虫洞是一条特殊的有向路径,当 FJ 从它的一头走到另一头后,他将被传送到过去的某个时刻.FJ 的每个农场包括 N(1<= ...

  3. Wormholes 最短路判断有无负权值

    Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes ...

  4. POJ 3259 Wormholes (最短路)

    Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 34302   Accepted: 12520 Descr ...

  5. poj 3259 Wormholes(最短路 Bellman)

    题目:http://poj.org/problem?id=3259 题意:一个famer有一些农场,这些农场里面有一些田地,田地里面有一些虫洞,田地和田地之间有路,虫洞有这样的性质: 时间倒流.问你这 ...

  6. POJ 3259 Wormholes 最短路+负环

    原题链接:http://poj.org/problem?id=3259 题意 有个很厉害的农民,它可以穿越虫洞去他的农场,当然他也可以通过道路,虫洞都是单向的,道路都是双向的,道路会花时间,虫洞会倒退 ...

  7. 洛谷2850 【Usaco2006 Dec】虫洞Wormholes SPFA

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

  8. 2019寒假练题计划——LibreOJ刷题计划 &《信息学奥赛一本通》提高版题目

    目录 2019.1.27 #10082. 「一本通 3.3 例 1」Word Rings 题意 思路 #10083. 「一本通 3.3 例 2」双调路径 题意 思路 #10084. 「一本通 3.3 ...

  9. LOJ 一本通一句话题解系列:

    第一部分 基础算法 第 1 章 贪心算法 1):「一本通 1.1 例 1」活动安排:按照结束时间排序,然后扫一遍就可以了. 2):「一本通 1.1 例 2」种树:首先要尽量的往区间重叠的部分种树,先按 ...

随机推荐

  1. 使用jquery获取父元素或父节点

    使用jquery获取父元素或父节点,比较简单,jquery提供了丰富的方法来让我们使用jquery获取父元素或父节点   jquery获取父元素方法比较多,比如parent(),parents(),c ...

  2. 【转载】DDD分层架构的三种模式

    引言 在讨论DDD分层架构的模式之前,我们先一起回顾一下DDD和分层架构的相关知识. DDD DDD(Domain Driven Design,领域驱动设计)作为一种软件开发方法,它可以帮助我们设计高 ...

  3. .net core 使用NPOI填充Word模板导出Word

    最近工作用到在Word模板插入数据库数据,导出一个带数据的Word文件,想起来之前操作Word都是用微软提供的Microsoft.Office.Interop.Word,而在最新的..NET CORE ...

  4. Flink--DateSet的Transformation简单操作

    flatMap函数 //初始化执行环境 val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment //加 ...

  5. idea创建项目报错(Maven execution terminated abnormally (exit code 1) )解决方案

    版本: idea14.0.2 java1.8 maven3.5 -------------------------------------------------------------------- ...

  6. Codeforces 596D Wilbur and Trees dp (看题解)

    一直在考虑, 每一段的贡献, 没想到这个东西能直接dp..因为所有的h都是一样的. #include<bits/stdc++.h> #define LL long long #define ...

  7. Centos 6.5 本地局域网基于HTTP搭建YUM

    服务端配置 init 3 文本  init5 图形  init 0 关机 init 1 重启 ls 查看  mkdir创建文件 关闭防火墙service iptables stop chkconfig ...

  8. NOIP2016提高组Day1T2 天天爱跑步 树链剖分 LCA 倍增 差分

    原文链接https://www.cnblogs.com/zhouzhendong/p/9275606.html 题目传送门 - 洛谷P1600 题目传送门 - LOJ#2359 题目传送门 - Vij ...

  9. git 错误解决

    1.今天 当我  执行  git add  somefile 的时候,出现 如下 错误: If no other git process is currently running, this prob ...

  10. redics在windows平台下的使用

    https://www.cnblogs.com/ding2011/p/4745732.html 一::下载    windows 下的redis: https://github.com/Service ...