poj 2983Is the Information Reliable?
来源:互联网 发布:淘宝pc端首页大小 编辑:程序博客网 时间:2024/05/17 22:48
差分约束用SPFA判断是否存在负数环 p的时候就是就是dis[B]- dis[A]>=w,dis[B]-dis[A]<=w,V就是dis[B]>=dis[A]+1
题目虽然没说A,B是1-n但是按照这样做过了。。。- -!!如果要的话,就hash一下呗
code:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
const int MAXB = 100011;
const int MAXN = 1010;
bool visit[MAXN];
int c[MAXN];
int dis[MAXN];
int n,m;
const int INF = 999999;
struct node{
int v,w;
node(int vv = 0,int ww = 0):v(vv),w(ww){}
};
vector<node> edge[MAXB];
int mins,maxs;
bool spfa(){
memset(visit,false,sizeof(visit));
memset(c,0,sizeof(c));
for(int i = 1;i<MAXN;i++)dis[i] = INF;
visit[0] = 1;
queue<int > qe;
qe.push(0);
c[0]++;
while(!qe.empty()){
int cur = qe.front();
qe.pop();
visit[cur] = 0;
for(int i = 0;i<edge[cur].size();i++){
if(dis[edge[cur][i].v]>edge[cur][i].w+dis[cur]){
dis[edge[cur][i].v] = dis[cur]+edge[cur][i].w;
c[edge[cur][i].v]++;
if(c[edge[cur][i].v]>n)return false;
if(!visit[edge[cur][i].v]){
qe.push(edge[cur][i].v);
visit[edge[cur][i].v] = 1;
}
}
}
}
return true;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF){
for(int i = 0;i<MAXN;i++)edge[i].clear();
int v,u,w;
mins = MAXN+1;
maxs = -1;
char p[20];
for(int i = 0;i<m;i++){
scanf("%s",p);
if(p[0]=='P'){
scanf("%d%d%d",&u,&v,&w);
edge[u].push_back(node(v,w));
edge[v].push_back(node(u,-w));
}else {
scanf("%d%d",&u,&v);
edge[v].push_back(node(u,-1));
}
}
for(int i = 1;i<MAXN;i++)edge[0].push_back(node(i,0));
if(spfa())printf("Reliable\n");
else printf("Unreliable\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(差分约束系统)
- oracle中字符转换
- Linux下,添加了#include 的文件编译时为什么要加 -ml ,gcc 加参数 -ml 是起什么作用呢
- 视觉的满足 三款来自美国的逼真视觉屏保
- C#打印(PrintDocument、PrintDialog、PageSetupDialog、PrintPreviewDialog)
- Maven3 安装使用(一)
- poj 2983Is the Information Reliable?
- linux那些事之二
- 正确重置msyql密码
- SQlite数据库的C编程接口(七) 数据库锁定(Database Locking) ——《Using SQlite》读书笔记
- c++获得本机ip地址
- 关于通达信数据格式的发布
- 1319 单词统计
- 360 一个让人又爱又恨的公司
- VC++ 工具篇