Is the information reliable?
Time limit:3000 Ms |
|
Memory limit:131072 K |
Total submissions:11125 |
|
Accepted:3492 |
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 lineNDefense 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 consistsMTips. Each tip is either precise or vague.
Precise tip is in the formP A B X
, Means Defense StationAIsXLight-years north of Defense StationB.
Vague tip is in the formV A B
, Means Defense StationAIs in the north of Defense StationB, 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 integersN(0 <N≤ 1000) andM(1 ≤M≤ 100000). The nextMLine 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 arrangeNDefense stations satisfying allMTips, otherwise output "unreliable ".
Sample Input
3 4P 1 2 1P 2 3 1V 1 3P 1 3 15 5V 1 2V 2 3V 3 4V 4 5V 3 5
Sample output
UnreliableReliabl
Given p a B w indicates that B is W km north of A, and v a B indicates that B is at least 1 km north of A. Ask if all the conditions can be met.
P can obtain B-A = W, that is, B-A <= W & a-B <= W, obtain B-A> = 1 from v a B, that is, a-B <=-1. Create a graph and use the shortest short circuit to determine whether a negative ring exists. The initial DIS should have all 0.
#include <cstdio>#include <cstring>#include <algorithm>struct node{ int u , v , w ;} p[300000];int dis[2000] , cnt ;void add(int u,int v,int w){ p[cnt].u = u ; p[cnt].v = v ; p[cnt++].w = w ;}int main(){ int i , j , n , m , u , v , w ; char str[10] ; while(scanf("%d %d", &n, &m)!=EOF) { cnt = 0 ; while(m--) { scanf("%s", str); if(str[0] == 'P') { scanf("%d %d %d", &u, &v, &w); add(u,v,-w); add(v,u,w); } else { scanf("%d %d", &u, &v); add(u,v,-1); } } memset(dis,0,sizeof(dis)); for(i = 1 ; i <= n ; i++) for(j = 0 ; j < cnt ; j++) if( dis[ p[j].v ] >dis[ p[j].u ] + p[j].w ) dis[ p[j].v ] = dis[ p[j].u ] + p[j].w ; for(j = 0 ; j < cnt ; j++) if( dis[ p[j].v ] > dis[ p[j].u ] + p[j].w ) break; if(j < cnt) printf("Unreliable\n"); else printf("Reliable\n"); }}
Poj2983 -- is the information reliable? (Differential constraint)