Poj 2983 Is the Information Reliable?
来源:互联网 发布:承德县德鸣大数据小镇 编辑:程序博客网 时间:2024/05/17 22:29
看了几天的差分约束,看懂的时候又发现自己走了弯路Orz
如果是第一次学习差分约束的话,建议在学会至少一个最短路算法的前提下去理解了单个不等式怎么转化成最短路的
具体的这个链接讲的特别好,我就不献丑了
要是能在脑海里动态的把不等式转化为一个有向路就更好了
#include<cstdio>#include<cstring>#include<vector>#include<queue>using namespace std;#define Edg pair<int,int>const int maxn = 1123;queue<int>Q;vector<Edg > edge[maxn];void init(int n){for(int i=0;i<=n;i++){edge[i].clear();}}void Link(int st,int ed,int v){edge[st].push_back(Edg(ed,v));}int cnt[maxn];int dis[maxn];bool inq[maxn];bool haver[maxn];bool vis[maxn];bool spfa(int st,int n){memset(cnt,0,sizeof(cnt));memset(dis,0x3f,sizeof(dis));memset(inq,0,sizeof(inq));Q.push(st);cnt[st]++;dis[st] = 0;inq[st] = true;while(Q.empty()==false){st = Q.front();Q.pop();vis[st] = true;inq[st] = false;for(vector<Edg >::iterator it = edge[st].begin();it!=edge[st].end();it++){int ed = it->first;int v = it->second;if(dis[st] + v < dis[ed]){dis[ed] = dis[st] + v;if(inq[ed] == false){inq[ed] = true;cnt[ed]++;if(cnt[ed] > n)return false;Q.push(ed);}}}}return true;}bool jud(int n){ memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++){ if(vis[i]==false && spfa(i,n)==false) return false; } return true;}int main(){int n,m;while(~scanf("%d %d",&n,&m)){init(n);char typ[4];int u,v,x;while(m--){scanf("%s %d %d",typ,&u,&v);if(*typ == 'P'){scanf("%d",&x);Link(u,v,x);Link(v,u,-x);}else{Link(v,u,-1);}}if(jud(n))puts("Reliable");elseputs("Unreliable");// for(int i=1;i<=n;i++){// printf(i<n?"%d ":"%d\n",dis[i]);// }}return 0;}
0 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(差分约束系统)
- 【SPOJ-PALIN】The Next Palindrome【模拟】
- Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition
- 工程中应用到的数字电路mos型和ttl型的门电路使用注意事项
- mssql有趣的注入 - niexinming
- 对List<T> 随机排序
- Poj 2983 Is the Information Reliable?
- android 中向手机端安装apk 的时候报出 INSTALL_FAILED_INSUFFICIENT_STORAGE 错误的解决方法
- hibernate annotation 之mappedBy 与 @JoinColumn区别
- Volley之https相关
- SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'customer' cannot be null
- ajax跨域问题
- vim基本命令
- 开始学习PHP
- CMake 基本使用方法--写CMakeList.txt,Compile ROS package