poj 2983——Is the Information Reliable?
来源:互联网 发布:linux xargs cat命令 编辑:程序博客网 时间:2024/06/16 17:02
差分约束
#include<cstdio>#include<iostream>#include<cstring>#include<queue>using namespace std;#define INF 10000001int n,m,cnt;int head[350001],v[350001],w[350001],next[350001];int dis[1005],vis[1005],output[1005];void add(int a,int b,int c){v[cnt]=b;w[cnt]=c;next[cnt]=head[a];head[a]=cnt++;}bool spfa(){for(int i=1;i<=n;i++)dis[i]=-INF;memset(vis,0,sizeof(vis));memset(output,0,sizeof(output));queue<int> q;q.push(0);dis[0]=0;vis[0]=1;while(!q.empty()){int u=q.front();q.pop();vis[u]=0;output[u]++;if(output[u]>n)return 0;for(int i=head[u];i!=-1;i=next[i])if(dis[v[i]]<dis[u]+w[i]){dis[v[i]]=dis[u]+w[i];if(!vis[v[i]]){vis[v[i]]=1;q.push(v[i]);}}}return 1;}int main(){while(~scanf("%d%d",&n,&m)){getchar();memset(head,-1,sizeof(head));cnt=0;char a[10];int x,y,z;for(int i=0;i<m;i++){scanf("%s",a);if(a[0]=='P'){scanf("%d%d%d",&x,&y,&z);add(y,x,z);add(x,y,-z);}else{scanf("%d%d",&x,&y);add(y,x,1);}}for(int i=1;i<=n;i++)add(0,i,0);if(spfa())cout<<"Reliable"<<endl;elsecout<<"Unreliable"<<endl;}return 0;}
- 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 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?
- hibernate注解的实现原理之1
- 八皇后排序,92种
- 透明窗口和窗口阴影
- 多线程中出现的一个面试题
- Magento邮件发送完美设置
- poj 2983——Is the Information Reliable?
- 面向对象设计原则
- 号称最快排序
- ibatis常用16条SQL语句
- 【c++笔记】二 我的main
- Linux workqueue疑问
- 很棒一个差分约束系统的理解,希望对你有帮助,果断转了
- linux中断处理的上半部和下半部
- Struts2 OGNL submit 配置key参数后异常