死活调不出来

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

吐血.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. 报错ERR_CONNECTION_REFUSED,如何解决(原创)

    当我访问我的一个后天地址的时候,突然出现了ERR_CONNECTION_REFUSED,但是之前是可以访问的. 我先ping了下这个网址,发现是OK的 然后我想可能是80端口有问题,也就是说可能是WE ...

  2. Codeforces Round #506 (Div. 3)

    题解: div3水的没有什么意思 abc就不说了 d题比较显然的就是用hash 但是不能直接搞 所以我们要枚举他后面那个数的位数 然后用map判断就可以了 刚开始没搞清楚数据范围写了快速乘竟然被hac ...

  3. 获取本地的ip,地址,code

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  4. 2018牛客网暑假ACM多校训练赛(第五场)H subseq 树状数组

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round5-H.html 题目传送门 - https://www.no ...

  5. BZOJ3531 [Sdoi2014]旅行 树链剖分 线段树

    原文链接:http://www.cnblogs.com/zhouzhendong/p/8080189.html 题目传送门 - BZOJ3531 题意概括 一棵树,n个节点,每一个节点两个值,一个颜色 ...

  6. F(x) 数位dp

    Problem Description For a decimal number x with n digits (AnAn-1An-2 ... A2A1), we define its weight ...

  7. Redis的工作流程

    从图上可以看出,当一个客户端访问服务器的时候,客户端请求会先到达Nginx,由Nginx负责对数据进行分发,上传到多个服务器,当用户访问到tomcat1的时候,会进行登陆验证并将session放入se ...

  8. Url地址重写

    一 什么是url重写URL 重写是截取传入 Web 请求并自动将请求重定向到其他 URL 的过程.比如浏览器发来请求 hostname/101.aspx ,服务器自动将这个请求中定向为http://h ...

  9. Git branch 出现"HEAD detached at head xxxxx"

    Git branch 出现"HEAD detached at head xxxxx" git branch <your-branch-name> xxxxx      ...

  10. 初识Linux系统

    1. pwd 显示现在所在位置 2. ls 显示目录下的文件 ls -a:显示隐藏文件(带 . 的就是隐藏文件): ls -a -l :每个文件夹的详细信息: ls > bbb (把查到的所有文 ...