多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > 【poj 2983】Is the Information Reliable? 差分約束

【poj 2983】Is the Information Reliable? 差分約束

來源:程序員人生   發布時間:2016-06-14 09:21:33 閱讀次數:2490次

題目:http://poj.org/problem?id=2983

Is the Information Reliable?
Time Limit: 3000MS Memory Limit: 131072K
Total Submissions: 12535 Accepted: 3943

Description

The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years ago. Draco established a line of defense called Grot. Grot is a straight line with N defense stations. Because of the cooperation of the stations, Zibu’s Marine Glory cannot march any further but stay outside the line.

A mystery Information Group X benefits form selling information to both sides of the war. Today you the administrator of Zibu’s Intelligence Department got a piece of information about Grot’s defense stations’ arrangement from Information Group X. Your task is to determine whether the information is reliable.

The information consists of M tips. Each tip is either precise or vague.

Precise tip is in the form of P A B X, means defense station A is X light-years north of defense station B.

Vague tip is in the form of V A B, means defense station A is in the north of defense station B, at least 1 light-year, but the precise distance is unknown.

Input

There are several test cases in the input. Each test case starts with two integers N (0 < N ≤ 1000) and M (1 ≤ M ≤ 100000).The next M line each describe a tip, either in precise form or vague form.

Output

Output one line for each test case in the input. Output “Reliable” if It is possible to arrange N defense stations satisfying all the M tips, otherwise output “Unreliable”.

Sample Input
3 4
P 1 2 1
P 2 3 1
V 1 3
P 1 3 1
5 5
V 1 2
V 2 3
V 3 4
V 4 5
V 3 5

Sample Output
Unreliable
Reliable

Source

POJ Monthly–2006.08.27, Dagger

題意:n個點,告知m個a,b間(有向)路徑長度或路徑長度>=1;求信息有誤否。

思路:差分束縛系統,建邊
1.a-b>=c  b-a>=-c
2.a-b>=1;
‘>=’建最小邊,spfa最長路,更新次數>=n—->有環—》false;

代碼

#include<iostream> #include<stdio.h> #include<vector> #include<string.h> #include<queue> using namespace std; int n,m; char s[3]; int aa,bb,cc; int tot; struct nod{ int x,v; nod(int xx,int vv) { x=xx,v=vv; }nod(){} }; vector<nod> lin[1005]; int vis[1005],d[1005]; int cnt[1005]; queue<int> Q; bool spfa() { Q.push(0); d[0]=0; vis[0]=1; while(!Q.empty()) { int now=Q.front(); Q.pop(); vis[now]=0; for(int i=0;i<lin[now].size();i++) { int v=lin[now][i].x; int vv=lin[now][i].v; if(d[v]==-1||d[v]<d[now]+vv) { d[v]=d[now]+vv; cnt[v]++; if(cnt[v]>n) { return false; } if(!vis[v]) { vis[v]=1; Q.push(v); } } } } return 1; } int main() { while(scanf("%d%d",&n,&m)!=EOF) { for(int i=1;i<=n;i++) { lin[i].clear(); d[i]=-1; vis[i]=0; cnt[i]=0; } for(int i=1;i<=m;i++) { scanf("%s",s); if(s[0]=='P') { scanf("%d%d%d",&aa,&bb,&cc); lin[aa].push_back(nod(bb,cc)); lin[bb].push_back(nod(aa,-cc)); } else if(s[0]=='V') { scanf("%d%d",&aa,&bb); lin[aa].push_back(nod(bb,1)); } } for(int i=1;i<n;i++) { lin[0].push_back(nod(i,0)); } if(!spfa()) printf("Unreliable\n"); else printf("Reliable\n"); } }
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: japan色系videos强行 | 免费成年人在线观看视频 | 精品福利国产 | 日本人视频-jlzz jlzz jlzz | 色悠久久久久综合欧美99 | 久草成人网| 波多野结衣免费一区二区三区香蕉 | 手机国产日韩高清免费看片 | 性欧美18xx | 欧美性videos高清精品 | 国产精品亚洲欧美日韩一区在线 | 中文字幕无线码一区二区三区 | 欧美人成在线观看ccc36 | 亚洲欧美视频网站 | 免费人成激情视频在线观看冫 | 欧美一区综合 | 国产精品久久久久一区二区三区 | 亚洲都市春色系列小说类型 | 免费在线h | 日韩精品欧美成人 | 伊人影视 | 美女爱爱网站 | 亚洲国产人成在线观看 | 波多野结衣手机视频一区 | 91一区二区三区 | xxxx日本高清 | 国产成人精品日本亚洲18图 | 国产欧美日韩免费一区二区 | 羞羞影视 | 黄色免费网站大全 | 欧美 日韩 国产 成人 在线观看 | 欧美日韩精 | 五月国产综合视频在线观看 | 欧美色图另类小说 | 欧美三级欧美做a爱 | 欧美成人aaaa免费高清 | 欧洲美女a视频一级毛片 | 丁香网五月| 亚洲国产日韩欧美在线vip1区 | 中文天堂最新版在线精品 | 午夜欧美激情 |