B-is the information reliable?
Time limit:3000 Ms
Memory limit:131072kb
64bit Io format:% I64d & % i64usubmit status
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 form V 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
# Include <stdio. h> # include <string. h> int n, m; int dis [1003]; int CNT; struct n {int U; int V; int W;} s [200003]; void add (int u, int V, int W) {s [CNT]. U = u; s [CNT]. V = V; s [CNT ++]. W = W;} void bellman_ford () {memset (DIS, 0, sizeof (DIS); int I, j; for (I = 1; I <= N; I ++) {for (j = 0; j <CNT; j ++) // check each edge {If (DIS [s [J]. v]> dis [s [J]. u] + s [J]. w) dis [s [J]. v] = dis [s [J]. u] + s [J]. W ;}}for (I = 0; I <CNT; I ++) {If (DIS [S [I]. v]> dis [s [I]. u] + s [I]. w) break;} if (I <CNT) printf ("unreliable \ n"); else printf ("reliable \ n");} int main () {int I, j; char ch; int U, V, W; while (scanf ("% d % * C", & N, & M )! = EOF) {CNT = 0; for (I = 0; I <m; I ++) {CH = getchar (); While (Ch! = 'P' & Ch! = 'V') {CH = getchar ();} If (CH = 'P') {scanf ("% d", & U, & V, & W); add (u, v,-1 * w); add (v, U, W);} else {scanf ("% d", & U, & V); add (u, v,-1) ;}} bellman_ford ();} return 0 ;}
Poj is the information reliable?