poj 2983 Is the Information Reliable?
来源:互联网 发布:育才行知小学对口初中 编辑:程序博客网 时间:2024/05/21 07:54
这题参考了别人的思路:
由于P A B X 指“确定A到B的距离(边权)为X”
从P A B X得到的差分系统为
dist[A] - dist[B] >= X && dist[A] - dist[B] <= X
等价于
dist[B] <= dist[A] - X && dist[A] <= dist[B] + X
则if(dist[B] > dist[A]-X) 松弛:dist[B] = dist[A]-X
由于 V A B指“只知道A到B的距离(边权)至少为1”
从V A B得到的差分系统为
dist[A] >= dist[B] +1
等价于
dist[B] <= dist[A] -1
则if(dist[B] > dist[A] -1) 松弛:dist[B] = dist[A] -1
#include <iostream>using namespace std; const int inf=1000000000;class{public: int s,e;}edge[200001];int N; int M;int dist[1001]; int w[200001]; int main(int i,int j){ while(cin>>N>>M) { memset(dist,0,sizeof(dist)); int pe=0; for(i=0;i<M;i++) { char pv; int a,b,x; getchar(); scanf("%c",&pv);if(pv=='P') { scanf("%d%d%d",&a,&b,&x); edge[pe].s=a; edge[pe].e=b; w[pe++]=x; edge[pe].s=b; edge[pe].e=a; w[pe++]=-x; } else if(pv=='V') { scanf("%d%d",&a,&b); edge[pe].s=a; edge[pe].e=b; w[pe++]=1; } } bool sign; for(j=0;j<N;j++) { sign=false; for(i=0;i<pe;i++) if(dist[ edge[i].e ] > dist[ edge[i].s ] - w[i]) { dist[ edge[i].e ] = dist[ edge[i].s ] - w[i]; sign=true; } if(!sign) break; } if(sign)cout<<"Unreliable"<<endl; //存在负权环 else cout<<"Reliable"<<endl; //不存在负权环 } return 0; }
- POJ 2983 Is The Information Reliable
- poj 2983 Is the Information Reliable?
- poj 2983 Is the Information Reliable?
- poj 2983Is the Information Reliable?
- poj 2983 Is the Information Reliable?
- poj 2983 Is the Information Reliable?
- poj 2983 Is the Information Reliable? (Bellman_Ford)
- POJ 2983 Is the Information Reliable?
- poj 2983 Is the Information Reliable?
- POJ 2983 Is the Information Reliable?
- POJ 2983 Is the Information Reliable?
- poj 2983--Is the Information Reliable?
- Poj 2983 Is the Information Reliable?
- POJ-2983 Is the Information Reliable?
- POJ 2983 Is the Information Reliable?
- poj 2983 Is the Information Reliable?
- poj Is the Information Reliable?
- POJ 2983 Is the Information Reliable(差分约束系统)
- struts2+ajax
- 从OCS 2007 R2迁移至Lync Server 2010
- C++模板学习
- 对网站速度优化的10个简单步骤
- 编程之美3.6 扩展
- poj 2983 Is the Information Reliable?
- OPPO Finder超薄设计体验:6.65mm不是极限
- java web 学习
- 网站打开速度优化:如何提高网页加载速度,提升网页打开速度
- POJ 2479(2段连续子序列和)
- 误差扩散算法
- Java字符编码总结
- ATL产生的RGS文件介绍
- [Linux][2012-08-06] 1 字节对齐