poj3259 bellman判正环
来源:互联网 发布:mac系统添加打印机 编辑:程序博客网 时间:2024/05/12 05:11
继续bellman判正环
注意path是双向的,虫洞是单向的
d[510]为各点与源点距离,然而没有源点。。。各点之间初始一样就可以
#include <iostream>#include <stdio.h>#include <algorithm>#include <queue>#include <cstring>#include <math.h>#include <map>#define FOR(i,j,k) for(int i=j;i<=k;i++)using namespace std;const int inf=10001;int n;int tot;struct node{ int x,y,t;}edge[5210];int d[510];bool bellman(){ for(int i=1;i<=n;i++) d[i]=inf; //确保每个点到源点距离一样就可以,d[i]=0也可以 bool flag; for(int i=1;i<=n-1;i++) { flag=false; for(int j=1;j<=tot;j++) if(d[edge[j].y]>d[edge[j].x]+edge[j].t) { d[edge[j].y]=d[edge[j].x]+edge[j].t,flag=true; //printf("%d ",d[edge[j].y]); } if(flag==false) break; } for(int j=1;j<=tot;j++) if(d[edge[j].y]>d[edge[j].x]+edge[j].t) return true; return false;}int main(){ int t; cin>>t; while(t--) { int m,w; tot=0; scanf("%d%d%d",&n,&m,&w); int s,e,temp; for(int i=1;i<=m;i++){ scanf("%d%d%d",&s,&e,&temp); tot++; edge[tot].x=s,edge[tot].y=e,edge[tot].t=temp; tot++; edge[tot].x=e,edge[tot].y=s,edge[tot].t=temp; } for(int i=m+1;i<=w+m;i++) { scanf("%d%d%d",&s,&e,&temp); tot++; edge[tot].x=s,edge[tot].y=e,edge[tot].t=-temp; } if(bellman()) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
0 0
- poj3259 bellman判正环
- poj3259 Bellman-Ford
- poj3259 bellman—ford
- [水]poj3259 (Bellman-ford)
- POJ3259 Wormholes(bellman)
- poj3259 Wormholes(Bellman)
- POJ3259《Wormholes》方法:Bellman-ford
- poj3259 Wormholes 最短路bellman
- poj3259 Wormholes --- bellman/spfa判负环
- POJ3259 Bellman-Ford算法 求负环
- poj3259 Wormholes (Bellman-Ford算法)
- POJ3259—Bellman-Ford算法实现
- POJ3259--Wormholes--Bellman-Ford算法经典题
- bellman判断负权回路--poj3259
- POJ3259 Wormholes(Bellman-ford 负环)
- poj3259 Wormholes(bellman负权处理)
- POJ3259(经典bellman判断负权)
- POJ3259 Wormholes(虫洞)(Bellman-floyd法解决)
- Remove Nth Node From End of List
- 我的博客之旅
- spring里面事务的传播属性和事务隔离级别
- 九蒸九晒熟地黄
- docker
- poj3259 bellman判正环
- 在MyEclipse安装目录看不完整的目录
- Android App Crash类型
- 德莱联盟(判断两个线段是否相交)
- LinkedList 方法知识点
- grep使用正则表达式查看与特定主机是否建立链接
- 备份mysq binlog shell
- Windows Azure系列-- 配置Azure Power Shell
- 1001 Exponentiation