F - Wormholes
#include<algorithm>
#include<queue>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<math.h>
using namespace std; const int maxn = ;
const int oo = 0xfffffff; struct node
{
int y, time;
node(int y, int t):y(y), time(t){}
};
vector<node> G[maxn];
int v[maxn]; int spfa(int s)
{
queue<int> Q;
Q.push(s); while(Q.size())
{
s = Q.front();Q.pop();
int len = G[s].size(); for(int i=; i<len; i++)
{
node q = G[s][i]; if(v[s]+q.time < v[q.y])
{
v[q.y] = v[s] + q.time;
Q.push(q.y);
}
} if(v[] < )
return ;
} return ;
} int main()
{
int T; scanf("%d", &T); while(T--)
{
int N, M, W, i, a, b, c; scanf("%d%d%d", &N, &M, &W); for(i=; i<=N; i++)
{
v[i] = oo;
G[i].clear();
}
v[] = ; for(i=; i<M; i++)
{
scanf("%d%d%d", &a, &b, &c);
G[a].push_back(node(b, c));
G[b].push_back(node(a, c));
} for(i=; i<W; i++)
{
scanf("%d%d%d", &a, &b, &c);
G[a].push_back(node(b, -c));
} int ans = spfa(); if(ans == )
printf("YES\n");
else
printf("NO\n");
} return ;
}
F - Wormholes的更多相关文章
- 【算法系列学习】SPFA邻接表最短路 [kuangbin带你飞]专题四 最短路练习 F - Wormholes
https://vjudge.net/contest/66569#problem/F 题意:判断图中是否存在负权回路 首先,介绍图的邻接表存储方式 数据结构:图的存储结构之邻接表 邻接表建图,类似于头 ...
- Mysql_以案例为基准之查询
查询数据操作
- POJ 3259 Wormholes (判负环)
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 46123 Accepted: 17033 Descripti ...
- ACM: POJ 3259 Wormholes - SPFA负环判定
POJ 3259 Wormholes Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu ...
- Wormholes
Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes ...
- poj 3259 Wormholes 判断负权值回路
Wormholes Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Java ...
- Wormholes(Bellman-ford)
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 33008 Accepted: 12011 Descr ...
- poj3259 bellman——ford Wormholes解绝负权问题
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 35103 Accepted: 12805 Descr ...
- Wormholes 分类: POJ 2015-07-14 20:21 21人阅读 评论(0) 收藏
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 35235 Accepted: 12861 Descr ...
随机推荐
- Orace数据库锁表的处理与总结<摘抄与总结一>
TM锁(表级锁)类型共有5种,分别称为共享锁(S锁).排它锁(X锁).行级共享锁(RS锁).行级排它锁(RX锁).共享行级排它锁(SRX锁) 当Oracle执行DML语句时,系统自动在所要操作的表上申 ...
- linux设置中文环境
确认当前环境 [root@Oracle11g ~]# df –h Filesystem Size Used Avail Use% Mounted on /dev/sda1 ...
- exp/imp 有很多弊端
弊端1. 空表 无法执行导出操作弊端2. 高版本的导出文件 无法使用 低版本的 oracle软件 导入 环境准备:create table test0707(n1 date); 认证弊端1 案例1. ...
- js 模板引擎 - 超级强大
本来没想写这篇文章,但是网上误导大众的文章太多了,所以今天就抽出半小时时间谈一下我对前端模板引擎的感受吧. 前端模板引擎相信大家都再熟悉不过了,市面上非常多的号称最好.最快.最牛逼的,随便就能找到一大 ...
- java_设计模式_适配器模式_Adapter Pattern(2016-08-09)
概念 将一个接口转换成客户希望的另外一个接口.(该模式使得原本不兼容的类可以一起工作). UML图 适配器模式有类的适配器模式和对象的适配器模式两种不同的形式. (1)对象的适配器模式结构图 (2)类 ...
- python split()黑魔法
split()用法: #!/usr/bin/python str = "Line1-abcdef \nLine2-abc \nLine4-abcd"; print str.spli ...
- access_token的获取方式
获取Access Token $appid = ""; $appsecret = ""; $url = "https://api.weixin.q ...
- 测试通过Word直接发布博文
这里是来自word 2013的一篇测试文章. 测试直接通过Word自带的bloger功能发布博客文章. 这里插入一张图片
- Lambda表达式中的表达式lambda和语句lambda区别
Lambda表达式可分为表达式lambda和语句lambda 表达式lambda:表达式位于 => 运算符右侧的lambda表达式称为表达式lambda (input parameters) = ...
- cocos creater 简单的跳跃动作。
因为最近一段时间有打算做一个2D游戏的想法,就顺便学习了一下cocos,很惊异的它的脚本编写语言竟然支持js,正好以前对js有一定的了解,就临时拿起来了. 这是来自官方的一个实例,不过在参考过程中,发 ...