title : 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 and 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 ' AR Rangement 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 was X light-years north of Defense station B.
Vague tip is in the form of V a B, means defense station A was in the north of Defense station B, at least 1 light-year, BU t the precise distance is unknown.
Input
There is several test cases in the input. Each test case is starts with the integers N (0 < n≤1000) and M (1≤m≤100000). The next M line is 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
Test Instructions : n points, tells M A, B (direction) path length or path length >=1; information error No.
idea : Differential constraint system, building edge
1.a-b>=c b-a>=-c
2.a-b>=1;
' >= ' built the smallest side, SPFA the longest road, update times >=n--> have ring-"false;
Code :
#include <iostream>#include <stdio.h>#include <vector>#include <string.h>#include <queue>using namespace STD;intN,m;Chars[3];intAA,BB,CC;intTotstructnod{intX,v; NodintXxintVV) {x=xx,v=vv; }nod () {}}; vector<nod>lin[1005];intvis[1005],d[1005];intcnt[1005]; Queue<int>Q;BOOLSPFA () {Q.push (0); d[0]=0; vis[0]=1; while(! Q.empty ()) {intNow=q.front (); Q.pop (); vis[now]=0; for(intI=0; I<lin[now].size (); i++) {intv=lin[now][i].x;intVV=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;}intMain () { while(scanf("%d%d", &n,&m)!=eof) { for(intI=1; i<=n;i++) {lin[i].clear (); d[i]=-1; vis[i]=0; cnt[i]=0; } for(intI=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(intI=1; i<n;i++) {lin[0].push_back (Nod (i,0)); }if(!SPFA ())printf("unreliable\n");Else printf("reliable\n"); }}
"Poj 2983" is the information Reliable? Differential constraints