死活调不出来

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

吐血.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. 安装Mysql5.6.19

    存在异常: ERROR (HY000): Can't connect to MySQL server on 'localhost' (10061) 原因:Mysql的服务没有启动 windows7启动 ...

  2. Mysql定时清空表

    1.设置开启event scheduler SET GLOBAL event_scheduler=1;   2.验证event_scheduler是否已经开启 show variables like ...

  3. 【C++ Primer | 15】继承的构造函数

    继承的构造函数 子类为完成基类初始化,在C++11之前,需要在初始化列表调用基类的构造函数,从而完成构造函数的传递.如果基类拥有多个构造函数,那么子类也需要实现多个与基类构造函数对应的构造函数. cl ...

  4. Ueditor设置默认字体、字号、行间距,添加字体种类(转)

    Ueditor默认字体.字号.行间距的修改: ueditor默认字号是16号,默认字体为sans-serif,默认行间距为5px,如下图所示: 首先,修改ueditor.all.js文件中如上图红框中 ...

  5. Go之viper配置

    这个模块功能强大,读取配置,命令行,监听配置改变. 堪称多面手,在k8s,docker中,都多有应用. 这套应用,主要包括cobra,pflag,viper三件套. 了解得差不多啦...:) pack ...

  6. ExceptionLess本地环境部署

    1.先去看看github上面本地流程说明 https://github.com/exceptionless/Exceptionless/wiki/Self-Hosting 比较总要的环境有 NET 4 ...

  7. C#版本与Framework的关系

    C# 1.0 released with .NET 1.0 and VS2002 (January 2002) C# 1.2 (bizarrely enough); released with .NE ...

  8. Linux 命令行敲命令 光标移动快捷键

    在单词之间跳转,使用Ctrl+左右键. Ctrl+a跳到本行的行首, Ctrl+e则跳到页尾. Ctrl+u删除当前光标前面的文字 ctrl+k-删除当前光标后面的文字 Ctrl+w和Alt+d-对于 ...

  9. ionic2/cordova自定义插件集成aar包

    一.准备自定义插件 1. 准备:安装plugman npm install -g plugman 2. 新建组件 plugman create --name MyPlugin --plugin_id ...

  10. 解决centos中vsftpd中文乱码

    系统环境 [root@augusite yum.repos.d]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) 软件版本 ...