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 ...
随机推荐
- 详细查看数据库SQL执行计划
DBCC DROPCLEANBUFFERS 清除数据缓存DBCC FREEPROCCACHE 清除执行计划缓存 SET SHOWPLAN_XML ON 此语句导致 SQL Server 不执行 Tr ...
- 那些年,我们一起学WCF--(8)Single实例行为
Single实例行为,类似于单件设计模式,所有可以客户端共享一个服务实例,这个服务实例是一个全局变量,该实例第一次被调用的时候初始化,到服务器关闭的时候停止. 设置服务为Single实例行为,只要设置 ...
- tomcat 正常启动,无法访问。且项目启动无问题。。。的解决办法。。
Eclipes解决方法: 1.右击项目,选择propreties选项 2.在弹出的首选项窗口的左侧选择“Web Project Settings” 3.修改context root:输入框,修改成自己 ...
- Deep Learning 学习随记(八)CNN(Convolutional neural network)理解
前面Andrew Ng的讲义基本看完了.Andrew讲的真是通俗易懂,只是不过瘾啊,讲的太少了.趁着看完那章convolution and pooling, 自己又去翻了翻CNN的相关东西. 当时看讲 ...
- UILabel的高度自适应
_content = [UILabel new]; _content.text = @"日落时分,沏上一杯山茶,听一曲意境空远的<禅>,心神随此天籁,沉溺于玄妙的幻境里.仿佛我就 ...
- Python中%s和%r的区别
早先使用Python工作的时候,对于格式化输出%s和%r的使用都是混着用的. 这一次就出错了: cu.execute("insert into ipPool values(null, '%r ...
- 未能解析目标框架“.NETFramework,Version=v4.0”的 mscorlib 错误的解决办法
查看项目属性,发现该项目的目标框架是.NET Framework 4 Client Profile ,而被引用的程序集的目标框架是.NET Framework 4,将该项目的目标框架修改成.NET F ...
- 用jq 做了一个排序
<ul id="cont"> <li data="5">5</li> <li data="1"&g ...
- ng-class css样式
<style> .error{background-color: red;} .warning{background-color: yellow;} </style> < ...
- gcc常用的编译选项
一.程序编译过程 程序编译的时候,要分四个阶段 : 1.预处理阶段,完成宏定义和include文件展开等工作: 2.根据编译参数进行不同程度的优化,编译成汇编代码: 3.用汇编器把汇编代码进一步生成目 ...