POJ Is the Information Reliable?

B - Is the Information Reliable?

Time Limit:3000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u

Submit 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 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
#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++) //检查每条边
        {
            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 %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 %d %d", &u, &v, &w );
                add(u, v, -1*w);
                add(v, u, w);
            }
            else
            {
                scanf("%d %d", &u, &v );
                add(u, v, -1 );
            }
        }
        bellman_ford();
    }
    return 0;
}
时间: 2024-12-14 17:05:28

POJ Is the Information Reliable?的相关文章

POJ 2983-Is the Information Reliable?(差分约束系统)

题目地址:POJ 2983 题意:有N个车站.给出一些点的精确信息和模糊信息.精确信息给出两点的位置和距离.模糊信息给出两点的位置.但距离大于等于一.试确定是否全部的信息满足条件. 思路:事实上就是让你推断是否存在负环.好久才看明确.对于精确消息.能够得出两个差分公式:dis[v] <= dist[u] - w  &&  dist[u] <= dist[v] + w.对于模糊信息.能够得出dis[v] <= dis[u] -1. PS:做差分约束感觉还是Bellman_f

POJ 题目2983 Is the Information Reliable?(差分约束)

Is the Information Reliable? Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 11859   Accepted: 3742 Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years ago. Draco established a line of defe

POJ 2983 Is the Information Reliable? 差分约束

裸差分约束. //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<sstream> #include<cmath> #include<

【POJ 2983】Is the Information Reliable?(差分约束系统)

[POJ 2983]Is the Information Reliable?(差分约束系统) Is the Information Reliable? Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 12244   Accepted: 3861 Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke ou

POJ 2983 Is the Information Reliable?

/* *POJ 2983 Is the Information Reliable? *差分约束系统 *(1)对于确定信息 P A B X, 有 A - B >= X && A - B <= X 即 B <= A + (-X) && A <= B + X * 即构成边<A, B, -X> 和 <B, A, X> *(2)对于不确定信息 V A B, 有 A - B >= 1, 即 B <= A + (-1) * 即构

POJ训练计划2983_Is the Information Reliable?(差分约束)

解题报告 思路: 求解: p:a-b=x v:a-b>=1 的方程 #include <iostream> #include <cstring> #include <cstdio> #include <queue> #define inf 0x3f3f3f3f using namespace std; struct node { int v,w,next; } edge[220000]; int head[1111],dis[1111],vis[111

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

题目: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. Dr

poj2983--Is the Information Reliable?(差分约束)

Is the Information Reliable? Time Limit: 3000MS   Memory Limit: 131072K 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 defe

Is the Information Reliable?(差分约束)

Is the Information Reliable?Crawling in process... Crawling failed Time Limit:3000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u Submit Status Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out