判环模板题 有了上一题的经验过得很轻松

除了因为spfa还不是很熟打错了两个字母 然后debug了一小会

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#define INF 0x3F3F3F3F
using namespace std; int size, head[], next[], point[], val[]; void init()
{
size = ;
memset(head, -, sizeof head);
} void add(int from, int to, int value)
{
point[size] = to;
val[size] = value;
next[size] = head[from];
head[from] = size++;
} bool spfa(int s, int n)
{
int dis[], time[];
bool vis[];
memset(dis, 0x3f, sizeof dis);
memset(time, , sizeof time);
memset(vis, false, sizeof vis); queue<int> q;
q.push(s);
dis[s] = ;
vis[s] = true;
while(!q.empty()){
int u = q.front();
q.pop();
vis[u] = false;
for(int i = head[u]; ~i; i = next[i]){
int j = point[i];
if(dis[j] > dis[u] + val[i]){
dis[j] = dis[u] + val[i];
if(!vis[j]){
//printf("dis[%d] = %d\n", j, dis[j]);
q.push(j);
vis[j] = true;
if(++time[j] > n) return true;
}
}
}
}
return false;
} int main()
{
int f, n, m, w;
scanf("%d", &f);
while(f--){
init();
scanf("%d%d%d", &n, &m, &w);
while(m--){
int a, b, value;
scanf("%d%d%d", &a, &b, &value);
add(a, b, value);
add(b, a, value);
}
while(w--){
int from, to, value;
scanf("%d%d%d", &from, &to, &value);
add(from, to , - value);
}
if(spfa(, n)) puts("YES");
else puts("NO");
}
return ;
}

kuangbin_ShortPath F (POJ 3259)的更多相关文章

  1. ACM: POJ 3259 Wormholes - SPFA负环判定

     POJ 3259 Wormholes Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu   ...

  2. poj - 3259 Wormholes (bellman-ford算法求最短路)

    http://poj.org/problem?id=3259 农夫john发现了一些虫洞,虫洞是一种在你到达虫洞之前把你送回目的地的一种方式,FJ的每个农场,由n块土地(编号为1-n),M 条路,和W ...

  3. POJ 3259 Wormholes(最短路,判断有没有负环回路)

    Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24249   Accepted: 8652 Descri ...

  4. POJ 3259——Wormholes——————【最短路、SPFA、判负环】

    Wormholes Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit St ...

  5. 最短路(Bellman_Ford) POJ 3259 Wormholes

    题目传送门 /* 题意:一张有双方向连通和单方向连通的图,单方向的是负权值,问是否能回到过去(权值和为负) Bellman_Ford:循环n-1次松弛操作,再判断是否存在负权回路(因为如果有会一直减下 ...

  6. POJ 3259 Wormholes(最短路径,求负环)

    POJ 3259 Wormholes(最短路径,求负环) Description While exploring his many farms, Farmer John has discovered ...

  7. Poj(3259),SPFA,判负环

    题目链接:http://poj.org/problem?id=3259 Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submis ...

  8. POJ 3259 Wormholes (Bellman_ford算法)

    题目链接:http://poj.org/problem?id=3259 Wormholes Time Limit: 2000MS   Memory Limit: 65536K Total Submis ...

  9. poj 3259 Wormholes

    题目连接 http://poj.org/problem?id=3259 Wormholes Description While exploring his many farms, Farmer Joh ...

随机推荐

  1. Apache Qpid Python 1.35.0 发布

    Apache Qpid Python 1.35.0 发布了,Apache Qpid (Open Source AMQP Messaging) 是一个跨平台的企业通讯解决方案,实现了高级消息队列协议.提 ...

  2. Airbase-ng帮助

    Airbase-ng 1.2 rc2 - (C) 2008-2014 Thomas d'Otreppe  Original work: Martin Beck  http://www.aircrack ...

  3. Python 安全类目推荐 (持续更新)

    推荐学习书目 › Learn Python the Hard Way › Python 学习手册 › Python Cookbook › Python 基础教程 Python Sites › PyPI ...

  4. html网页标题

    HTML代码 <html> <head> <!--<title>定义网页标题,显示在浏览器的标题--> <title>网页标题</ti ...

  5. UI基础:DataPersistent.沙盒

    沙盒是系统为每一个应用程序生成的一个特定文件夹,文件夹的名字由一个十六进制数据组成,每一个应用程序的沙盒文件名都是不一样的,是由系统随机生成的. 沙盒主目录: NSString *homePath = ...

  6. Extjs学习笔记(-):ComboBox联动

    http://www.cnblogs.com/wumin97136/archive/2007/12/24/1012720.html http://examples.ext.net/ http://ex ...

  7. magento二次开发的基本步骤分享

    Magento后台添加新模块的体会 确定命名空间(Namespace)和模块(Modulename)的命名: 在app/etc/modules/ 路径下,创建 Namespace_Modulename ...

  8. Nexus仓库构建

    1 . 私服简介 私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件.有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库:否则,私服请求外部 ...

  9. log4j常见问题

    1.日志文件不能生成日期后缀 需求:想要生成的文件是以日期格式为后缀或者结尾的. 设置: log4j.appender.appenderName.DatePattern='.'yyyy-MM-dd 也 ...

  10. lanuchy快捷操作

    down arrow: display history shift+delete: remove the item from the distory