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 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
Reliabl

给出了 P a  b  w 表示 b在a以北w公里, V a  b 表示 b在a北边,最少1公里,问所有 的条件可不能够所有满足。

由P 能够得到 b - a = w 也就是b - a <= w  &&  a - b <= w ,由 V a  b 得到 b - a >= 1 也就是 a - b <= -1 ;建图,使用最短路,推断是否会有负环。初始dis要所有为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?(差分约束)的更多相关文章

  1. POJ 2983 Is the Information Reliable? 差分约束

    裸差分约束. //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #i ...

  2. POJ2983 Is the Information Reliable?

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=267#problem/B                        B -  ...

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

    题目地址:POJ 2983 题意:有N个车站.给出一些点的精确信息和模糊信息.精确信息给出两点的位置和距离.模糊信息给出两点的位置.但距离大于等于一.试确定是否全部的信息满足条件. 思路:事实上就是让 ...

  4. Is the Information Reliable?(差分约束系统)

    http://poj.org/problem?id=2983 题意:给出M条信息,判断这些信息的正确性.(1)V A B :表示A,B之间的距离>=1; (2)P A B X :表示A B之间的 ...

  5. Is the Information Reliable?(差分约束)

    Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years a ...

  6. POJ 2983 Is the Information Reliable? 信息可靠吗 (差分约束,spfa)

    题意:有n个站排成一列,针对每个站的位置与距离关系,现有多个约束条件,约束条件分两种:(1)确定的.明确说明站a距离站b多少个单位距离.(2)不确定的.只知道a在b的左边至少1个单位距离.  根据已知 ...

  7. POJ 2983:Is the Information Reliable?(差分约束)

    题目大意:有n个点在一条直线上,有两类关系:P(x,y,v)表示x在y北边v距离处,V(x,y)表示x在y北边至少1距离出,给出一些这样的关系,判断是否有矛盾. 分析: 差分约束模板题,约束条件P:a ...

  8. POJ 2983 Is the Information Reliable? 依旧差分约束

    http://poj.org/problem?id=2983 题目大意: 星际大战开始了.你购买了情报,需要判断它的准确性.已知地方的根据地在由南向北排成一条直线.P A B X,表示A在B北面距离X ...

  9. 【poj2983】 Is the Information Reliable?

    http://poj.org/problem?id=2983 (题目链接) 一个SB错误TLE了半个小时... 题意 一条直线上有n个点,给出m条信息,若为P则表示点A在点B的北方X米,若为V则表示A ...

随机推荐

  1. 【BZOJ 2744】 2744: [HEOI2012]朋友圈 (最大团,二分图匹配,构图)

    2744: [HEOI2012]朋友圈 Description 在很久很久以前,曾经有两个国家和睦相处,无忧无虑的生活着.一年一度的评比大会开始了,作为和平的两国,一个朋友圈数量最多的永远都是最值得他 ...

  2. VB查询数据库之登陆窗体——机房收费总结(一)

    机房收费系统已经做了很长一段时间了,虽然到目前为止,仍然没有结束,但已经结节尾声了.我感觉现在有必要回首总结一下整个机房收费系统. 除了结账做了一半,报表接触一点之外,其他的都基本上差不多了.从做过的 ...

  3. 【动态规划】【滚动数组】【搜索】Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion

    显然将扩张按从大到小排序之后,只有不超过前34个有效. d[i][j]表示使用前i个扩张,当length为j时,所能得到的最大的width是多少. 然后用二重循环更新即可, d[i][j*A[i]]= ...

  4. python基础之数据类型之数字、字符串、列表

    数据类型及内置方法 一.数字类型 整数型(int) 1.用途:年龄,号码等 2.定义:age = 10   age = int(10) x = int(’11’)   int只能转换纯数字的字符串 3 ...

  5. redis源码解析之dict数据结构

    dict 是redis中最重要的数据结构,存放结构体redisDb中. typedef struct dict { dictType *type; void *privdata; dictht ht[ ...

  6. (小规模)b牌棋盘完美覆盖数

    (小规模)b牌棋盘完美覆盖数 考虑一个普通的国际象棋棋盘,它被分成8*8(8行8列)的64个正方形.设有形状一样的多米诺骨牌,每张牌恰好覆盖棋盘上相邻的两个方格(即1*2的骨牌).那么能否把32个这样 ...

  7. 关于abstract class 和 interface

    1.abstract class 在 Java 语言中表示的是一种继承关系,一个类只能使用一次继承关系.但是,一个类却可以实现多个interface. 2.在abstract class 中可以有自己 ...

  8. CentOS 6.9下KVM虚拟机网络Bridge(网桥)方式与NAT方式详解(转)

    摘要:KVM虚拟机网络配置的两种方式:NAT方式和Bridge方式.Bridge方式的配置原理和步骤.Bridge方式适用于服务器主机的虚拟化.NAT方式适用于桌面主机的虚拟化. NAT的网络结构图: ...

  9. 使用参数化查询防止SQL注入漏洞

    参数化查询防止SQL注入漏洞 看别人的登录注册sql语句有没漏洞即可 Where  name=‘admin’ or ‘1=1’ and password=’123’; 可以Or ‘1=1’就是漏洞 h ...

  10. jQuery中的Ajax全局事件

    Ajax全局事件 全局事件会在有ajax请求的情况下触发. 方法名称 说明 ajaxStart(callback) Ajax请求开始时执行的函数 ajaxStop(callback) Ajax请求结束 ...