POJ 3259 Wormholes
来源:互联网 发布:淘宝旺旺链接 编辑:程序博客网 时间:2024/06/06 03:00
题意:判断是否存在负环
#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define Max 0xfffffffstruct node{ int from; int to; int t;}s[10010];int dis[10010];bool bellmanford(int n,int p){ int i,j; bool flag; for(i = 0; i <= n; i++) { flag = false; for(j = 0; j < p; j++) { if(dis[s[j].to] > dis[s[j].from] + s[j].t) { dis[s[j].to] = dis[s[j].from] + s[j].t; flag = true; } } if(!flag) break; } if(!flag) return false; else return true;}int main(){ int f; int i,a,b,c; int n,m,w; scanf("%d",&f); while(f--) { int n,m,w; scanf("%d%d%d",&n,&m,&w); int p = 0; memset(dis,Max,sizeof(dis)); //边是双向的 for(i = 0; i < m; i++) { scanf("%d%d%d",&a,&b,&c); s[p].from = a; s[p].to = b; s[p+1].from = b; s[p+1].to = a; s[p++].t = c; s[p++].t = c; } //虫洞传送的路径,注意权值为负 for(i = 0; i < w; i++) { scanf("%d%d%d",&a,&b,&c); s[p].from = a; s[p].to = b; s[p++].t = -c; } if(bellmanford(n,p)) printf("YES\n"); else printf("NO\n"); } return 0;}
0 0
- poj 3259 Wormholes //SPFA
- POJ 3259 Wormholes
- poj 3259 Wormholes
- POJ 3259 Wormholes
- POJ 3259 Wormholes
- Poj 3259 Wormholes
- poj 3259 Wormholes
- poj-3259-Wormholes
- POJ-3259-Wormholes
- POJ 3259 Wormholes bellman_ford
- poj 3259 Wormholes
- poj 3259 Wormholes
- POJ 3259 Wormholes
- POJ 3259 Wormholes
- POJ 3259 Wormholes
- poj 3259 Wormholes
- POj 3259 Wormholes
- POJ 3259 Wormholes
- 适配iOS7 — UISearchBar
- 微博应用框架开发文档
- entity framework 6 自己编写的通用数据类
- python-requests 必需如下使用才能保持keep-alive
- skiplist
- POJ 3259 Wormholes
- FileWriter类总结
- java int数组转为long数组
- Hibernate学习之事务
- Facebook社交业务进军中国内地,困难重重
- [GitHub][2014-05-13 18:01:56]jfinal
- linux按键中断驱动示例
- Java中都通用文件下载
- C#反射机制