Is the information reliable? (Differential constraint)

Source: Internet
Author: User

Is the information reliable?Crawling in process...Crawling failedTime limit:3000 MsMemory limit:131072kb64bit Io format:% I64d & % i64u

Submitstatus

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

UnreliableReliable
 
Meaning: There are n stations that provide precise information and fuzzy information about some points. The precise information gives the location and distance of two points. The fuzzy information gives the location of two points, but the distance is greater than or equal to one. Try to determine if all information meets the conditions
 
Idea: for precise information, two difference conditions can be obtained, B-A = C; can be converted to B-A> = C & a-B <=-C; (because it is accurate information, it is necessary to establish a bidirectional edge)
For Fuzzy Information, only one difference condition can be obtained, which can be converted into B-A <= 1; so a <= B-1; B To A has a side with a length of-1; (blur information to create a unidirectional edge)
 
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;#define inf 9999999999;struct node{    int u,v,w;} edge[200000];int dis[200000];int n,m,cnt;int Bellman_ford(){    int i,j;    int flag;    memset(dis,0,sizeof(dis));    for(i=0;i<n;i++)    {        flag = 0;        for(j=0;j<cnt;j++)        {            if(dis[edge[j].v]>dis[edge[j].u]+edge[j].w)            {                dis[edge[j].v]=dis[edge[j].u]+edge[j].w;                flag=1;            }        }        if(!flag)            break;    }    for(j=0;j<cnt;j++)    {        if(dis[edge[j].v]>dis[edge[j].u]+edge[j].w)            return 1;    }    return 0;}int main(){    int i,j;    int u,v,w;    char str;    while(~scanf("%d %d",&n,&m))    {        cnt=0;        for(i=0; i<m; i++)        {            getchar();            scanf("%c",&str);            if(str=='P')            {                scanf("%d %d %d",&u,&v,&w);                edge[cnt].u=u;                edge[cnt].v=v;                edge[cnt].w=w;                cnt++;                edge[cnt].u=v;                edge[cnt].v=u;                edge[cnt].w=-w;                cnt++;            }            else            {                scanf("%d %d",&u,&v);                edge[cnt].u=v;                edge[cnt].v=u;                edge[cnt].w=-1;                cnt++;            }        }        if(Bellman_ford())            puts("Unreliable");        else            puts("Reliable");    }    return 0;}


Zookeeper

Is the information reliable? (Differential constraint)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.