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 ...
随机推荐
- Android 官方新手指导教程
一.开始 1.建立第一个应用程序 依赖关系和先决条件 Android SDK ADT Plugin 20.0.0 或更高 (如果你使用eclipse的话) 欢迎来到Android应用程序开发! 这一节 ...
- There is no ID/IDREF binding for IDREF
http://blog.csdn.net/greensurfer/article/details/7596219
- .net RAW(16)与GUID互相转换
.net 1.raw转guidnew guid(byte[] id);2.guid转rawGuid result;string ids = BitConverter.ToString(result.T ...
- CoreBluetooth
Core Bluetooth的基本常识 每个蓝牙4.0设备都是通过服务(Service)和特征(Characteristic)来展示自己的 一个设备必然包含一个或多个服务,每个服务下面又包含若干个特征 ...
- C#winform程序自定义鼠标样式
public void SetCursor(Bitmap cursor, Point hotPoint) { int hotX = hotPoint.X; int hotY = hotPoint.Y; ...
- 【BZOJ2809】【splay启发式合并】dispatching
Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 Master以外,每名忍者都有且仅有一个上级. ...
- javascript——归并方法
<script type="text/javascript"> //ECMAScript5 还新增了2个归并数组的方法:reduce()和reduceRight(). ...
- Python自动化运维之26、Web框架本质、MVC与MTV
一.Web框架本质 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. #!/usr/bin/env python #coding:ut ...
- python有序字典实现代码
class MyDict(dict): #有序字典实现 def __init__(self): self.li = [] super(MyDict,self).__init__() def __set ...
- Python Tutorial 学习(三)--An Informal Introduction to Python
3.1. 将Python用作计算器 3.1.1. Numbers 数 作为一个计算器,python支持简单的操作, '+','-','*','/'地球人都知道的加减乘除. ()可以用来改变优先级,同数 ...