poj 3259 Wormholes
来源:互联网 发布:淘宝有些不能用花呗 编辑:程序博客网 时间:2024/06/09 17:39
#include<stdio.h>#include<string.h>#define INF 0x3f3f3f3fstruct edge{ int fr,to,val;}e[5210];//邻接表int n,m,w,l;bool bellman(){ int dis[510],f,t,v; memset(dis,INF,sizeof(dis)); dis[1]=0; for(int i=0;i<n-1;++i)//n-1次循环,松弛操作(一次所有边的遍历) { bool over=true;//一次循环中没有发生松弛,下一次也不会发生,每次松弛有赖于前面的松弛。 for(int j=0;j<l;++j) { f=e[j].fr; t=e[j].to; v=e[j].val; if(dis[f]+v<dis[t]) { dis[t]=dis[f]+v; over=false; } } if(over) break; } for(int i=0;i<l;++i) { f=e[i].fr; t=e[i].to; v=e[i].val; if(dis[f]+v<dis[t]) return true; } return false;}int main(){ int f; scanf("%d",&f); while(f--) { int i,f,t,v; l=0; scanf("%d%d%d",&n,&m,&w); for(i=0;i<m;i++) { scanf("%d%d%d",&f,&t,&v); e[l].fr=f; e[l].to=t; e[l].val=v; ++l; e[l].fr=t; e[l].to=f; e[l].val=v; ++l; } for(i=0;i<w;++i) { scanf("%d%d%d",&f,&t,&v); e[l].fr=f; e[l].to=t; e[l].val=0-v; ++l; } if(bellman()) 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
- iOS开发--AFNetworking数据请求
- 错误提示:accept: Invalid argument
- 位运算符
- Linux下抓包工具tcpdump应用详解
- 游戏开发要学什么?游戏开发如何快速入门就业?
- poj 3259 Wormholes
- jdk5以上自带线程池使用并返回结果
- 深入理解Git (六) - 松散对象
- SpringMVC学习系列(7) 之 格式化显示
- 前置和后置自增以及解引用重载函数(++、--、*)
- UVa 10617 Again Palindrome(回文串区间DP)
- ZIGBEE:发送函数AF_DataRequest详解
- android快捷开发框架xUtils简介和使用
- 数据结构 - 双向列表与循环列表