poj 2983 Is the Information Reliable?
来源:互联网 发布:下载个淘宝网 编辑:程序博客网 时间:2024/05/18 01:47
等号的情况可以转换成不等式
a=b 就可以表示成a>=b b>=a
约束条件写出来就用bellman-ford
需要注意的是要构造超级源点
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<limits.h>struct edge{int u,v,w;}edges[500001];char ch[100];int dist[1001];int main(){ int n,mm,m; int u,v; while(scanf("%d%d",&n,&mm)==2){ m=0; for(int i=1;i<=mm;i++){ scanf("%s",&ch); if (ch[0]=='V'){ m++; scanf("%d%d",&edges[m].v,&edges[m].u); edges[m].w=-1; } if (ch[0]=='P'){ m++; scanf("%d%d%d",&edges[m].v,&edges[m].u,&edges[m].w); edges[m].w=-edges[m].w; m++; edges[m].u=edges[m-1].v;edges[m].v=edges[m-1].u; edges[m].w=-edges[m-1].w; } } bool flag=true; int u,v; for (int i=0;i<=n;i++) dist[i]=0; dist[1]=0; for (int i=1;i<=n;i++){ for (int j=1;j<=m;j++){ if (dist[edges[j].v]>dist[edges[j].u]+edges[j].w) dist[edges[j].v]=dist[edges[j].u]+edges[j].w; } } for (int j=1;j<=m;j++){ if (dist[edges[j].v]>dist[edges[j].u]+edges[j].w) { flag=false; break; } } if (!flag) printf("Unreliable\n"); else printf("Reliable\n"); } 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(差分约束系统)
- 解析 SQL Server 的存储过程
- 算法导论——第一章
- 实现省市级的 二级联动
- SQL基础4——分组与分组函数
- 无名结构体的一个妙用
- poj 2983 Is the Information Reliable?
- 应用C++成员指针需要遵守的两个规则
- 使用数据库连接池优化程序性能
- 算法导论——第二章——堆排序
- Qt写的行数统计工具[更新Dll]
- 使用数据库连接池优化程序性能
- Ubuntu-11.10之八 profile与bashrc的分析
- 算法导论——第三章——优先级队列(以堆为思想)
- ofstream建立文件问题