poj Is the Information Reliable?
来源:互联网 发布:日本ip代理地址和端口 编辑:程序博客网 时间:2024/05/21 11:08
差分约系统。
至于等于就大于等于且小于等于。
发现以前的spfa板子有问题,点要提前出队,才能判自环。
code:
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<queue>#include<algorithm>using namespace std;struct node{ int x,y,c,next;}a[2110000];int len=0,last[500010];int n,m;void ins(int x,int y,int c){ a[++len].x=x;a[len].y=y;a[len].c=c; a[len].next=last[x];last[x]=len;}queue<int> q;int d[500010],ru[500010];bool u[500010];bool spfa(){ memset(d,0,sizeof(d)); memset(ru,0,sizeof(ru)); memset(u,true,sizeof(u)); for(int i=0;i<=n;i++) q.push(i); while(!q.empty()) { int x=q.front();u[x]=false; for(int i=last[x];i;i=a[i].next) { int y=a[i].y; if(d[x]+a[i].c>d[y]) { d[y]=d[x]+a[i].c; ru[i]++;if(ru[i]>n) return false; if(!u[y]) u[y]=true,q.push(y); } } q.pop(); } return true;}int main(){ while(scanf("%d %d",&n,&m)!=EOF) { memset(last,0,sizeof(last));len=0; for(int i=1;i<=m;i++) { char s[5]; scanf("%s",s+1); if(s[1]=='P') { int x,y,c;scanf("%d %d %d",&x,&y,&c); ins(x,y,c);ins(y,x,-c); } else { int x,y;scanf("%d %d",&x,&y); ins(x,y,1); } } if(spfa()) printf("Reliable\n"); else printf("Unreliable\n"); }}
阅读全文
2 0
- poj Is the Information Reliable?
- 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?
- Is the Information Reliable?
- 前端之js-openlayers4
- Visual Studio Code v1.15发布
- python——django使用mysql数据库(二)
- Android代码中遇到的一些警告或问题汇总
- spark学习-20-Spark的sample理解
- poj Is the Information Reliable?
- 在 kubectl 中使用 Service Account Token
- 1199:A+B Problem
- python模块之StringIO
- 拉格朗日对偶性
- 如何修改eclipse的默认工作空间
- python
- 【java面试系列之网络编程】TCP和UDP的区别、TCP协议的三次握手和四次挥手、TCP协议的通信状态、网络编程时的同步、异步、阻塞、非阻塞、进程间的通信方式、TCP的流量控制和拥塞控制
- Spring注解式事务解析