POJ 3259 Wormholes
来源:互联网 发布:mac snow ball powder 编辑:程序博客网 时间:2024/06/06 17:54
农民有很多农场,农场之间有路,还有虫洞……
input :
23 3 11 2 21 3 42 3 13 1 3第一行:测试数据组
第二行:N,M,W:N=农场数,M=农场之间路,W=虫洞路。
我的理解大概就是能否检测到 负权回路,然后农民回去就看到自己。
#include<cstdio>#include<cstring>#include<algorithm>#define Size 1e8using namespace std;int n,N;struct lx{ int i,j,x;}a[5502];int bellman(){ int i,j,k,d[1001]; for(k=1;k<n;k++) { bool ok=0; for(i=0;i<N;i++) { if(d[a[i].i]>d[a[i].j]+a[i].x) d[a[i].i]=d[a[i].j]+a[i].x,ok=1; } if(!ok)break; } for(i=0;i<N;i++) { if(d[a[i].i]>d[a[i].j]+a[i].x) return 0; } return 1;}int main(){ int t,m,w,x,y,k; scanf("%d",&t); while(t-->0) { scanf("%d%d%d",&n,&m,&w); int i=0; while(m-->0) { scanf("%d%d%d",&x,&y,&k); a[i].i=x,a[i].j=y,a[i++].x=k; a[i].i=y,a[i].j=x,a[i++].x=k; } while(w-->0) { scanf("%d%d%d",&x,&y,&k); a[i].i=x,a[i].j=y,a[i++].x=-k; } N=i; if(bellman())printf("NO\n"); else printf("YES\n"); }}
- 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
- oracle之中表的创建与操作 table create
- keyboard show and hide resize view
- 调整ubuntu server 12.04.2分辨率
- 简解:浏览器原理
- 转载_Linux procfs开发指南(部分翻译并做了精简)
- POJ 3259 Wormholes
- Extjs基本业务处理事件之MVC
- 展开缩放效果JS函数
- Poj 3687 Labeling Balls——拓扑排序
- 委托实现窗口间同步传值
- jQuery validation 应用实例
- BX9054: 各浏览器对 document.execCommand 方法的首参数可选值范围存在差异
- [Chrome]谷歌浏览器插件开发:HelloChrome插件的开发过程
- 关于ubuntu下搭建tftp服务器