题目传送门

题目大意:有F组数据,N表示有N点,M表示有M条边,走一遍边需要花费Ti个时间,还有W个虫洞,可以向前回溯Ti时间,求能否从1点出发,经过一些路或虫洞回到1点后时间为负。

建图后用SPFA判负环即可。

code:

#include <cstdio>
#include <cstring>
using namespace std; int read()
{
char c;while(c=getchar(),c<''||c>'');
int x=c-'';while(c=getchar(),c>=''&&c<='')x=x*+c-'';
return x;
} int T;
int N,M,W;
int x,y,c; struct list{
int head[],nxt[],To[],W[],cnt;
void fc(){memset(head,-,sizeof head);memset(nxt,-,sizeof nxt);cnt=;} void add(int x,int y,int c)
{
W[cnt]=c;To[cnt]=y;
nxt[cnt]=head[x];
head[x]=cnt;
cnt++;
}
}MP; bool flag;
int dist[],vis[];
void SPFA(int now)
{
if(flag)return ;
vis[now]=;
for(int i=MP.head[now];i!=-;i=MP.nxt[i]){
if(dist[now]+MP.W[i]<dist[MP.To[i]]){
if(vis[MP.To[i]]){flag=true;return ;}
dist[MP.To[i]]=dist[now]+MP.W[i];
vis[MP.To[i]]=;SPFA(MP.To[i]);
}
}
vis[now]=;
return ;
} int main()
{
T=read();
register int i,j;
while(T--){
N=read(),M=read(),W=read();
MP.fc();
for(i=;i<=M;i++){
x=read(),y=read(),c=read();
MP.add(x,y,c);
MP.add(y,x,c);
}
for(i=;i<=W;i++){
x=read(),y=read(),c=read();
MP.add(x,y,-c);
}
memset(vis,,sizeof vis);memset(dist,,sizeof dist);dist[]=;
flag=;SPFA();
if(flag)puts("YES");
else puts("NO");
}
}

POJ3259_Wormholes_KEY的更多相关文章

随机推荐

  1. jQuery插件开发精品教程,让你的jQuery提升一个台阶(转)

    原文:http://www.cnblogs.com/Wayou/p/jquery_plugin_tutorial.html 要说jQuery 最成功的地方,我认为是它的可扩展性吸引了众多开发者为其开发 ...

  2. [原]如何在Android用FFmpeg+SDL2.0之同步音频

    同步音频的原理可以参考:http://dranger.com/ffmpeg/tutorial05.html  本文是在 [原]如何在Android用FFmpeg+SDL2.0之同步视频 的基础上面继续 ...

  3. 静态路由解决双外卡,PC做路由器的实现

    1,曾经医院,有两个网卡,一个内,一个外,但都有网关(192.168.1.246. 192. 168.6.1) 这样同一时候开启就会出现网络不通. 当时并没有细究原因. 这次医院信息化项目上马,我学到 ...

  4. HDU 6395 Sequence 【矩阵快速幂 && 暴力】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others)   ...

  5. Python re模块正则表达式

  6. java8的4大核心函数式接口

    //java8的4大核心函数式接口//1.Consumer<T>:消费性接口//需求:public void happy(double money, Consumer<Double& ...

  7. 使用@AspectJ注解开发Spring AOP

    一.实体类: Role public class Role { private int id; private String roleName; private String note; @Overr ...

  8. STM32F103 ucLinux开发之二(内核启动汇编代码分析)

    start_kernel之前的汇编代码分析 Boot中执行下面两句话之后,进入uclinux内核. theKernel = (void (*)(int, int, unsigned int))((ui ...

  9. Unity 游戏框架搭建 (二十三) 重构小工具 Platform

    在日常开发中,我们经常遇到或者写出这样的代码 var sTrAngeNamingVariable = "a variable"; #if UNITY_IOS || UNITY_AN ...

  10. 自己封装了的AlertController

    一直觉得使用系统这个东西写起来特别麻烦,每次都要写一大推东西,还是重复的,今天抽了点时间自己重新封装了一下,解决了自己的强迫症...,不多说,直接上代码了. 1.自己定义了一个名为XBZ的UIAler ...