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. css-移动&缩放元素

    transform 属性向元素应用 2D 或 3D 转换.该属性允许我们对元素进行旋转.缩放.移动或倾斜. 用法:object.style.transform="rotate(7deg)&q ...

  2. 【数据结构(高效)/暴力】Parencodings

    [poj1068] Parencodings Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26686   Accepted ...

  3. 【枚举】【SPFA】Urozero Autumn Training Camp 2016 Day 5: NWERC-2016 Problem I. Iron and Coal

    那个人派出的队伍的行走的路径一定前半程是重合的,后半程分叉开来. 于是预处理每个点离1号点的最短路,到最近的铁的最短路,到最近的煤的最短路.(三次BFS / SPFA)然后枚举分岔点,尝试更新答案即可 ...

  4. 【BFS】bzoj2252 [2010Beijing wc]矩阵距离

    要注意一开始将所有为'1'的点入队,然后通过一次BFS去更新所有点的距离,直到无法更新为止. #include<cstdio> #include<queue> #include ...

  5. 【KMP模板】POJ3461-Oulipo

    [题意] 找出第一个字符串在第二个字符串中出现次数. [注意点] 一定要先将strlen存下来,而不能每次用每次求,否则会TLE! #include<iostream> #include& ...

  6. 1.创建spring cloud父工程和子模块

    创建父工程 idea创建父工程 idea创建一个工程.父工程管理公共资源 添加子模块 选择添加到父工程里面spring_cloud_parent 相应的子模块添加到父工程的pom.xml文件里

  7. [NOIP2013 花匠] 新人解题报告

    本来按照老师的要求,我学OI的第一份解题报告应是在寒假完成的关于数据结构的基础题,但由于身体原因当时未能完成,那么就在省选赛前临时写几篇吧…… 题目描述 花匠栋栋种了一排花,每株花都有自己的高度.花儿 ...

  8. MYSQL复习笔记9-存储过程

    date: 20140208auth: Jin参考引用:http://blog.sina.com.cn/s/blog_52d20fbf0100ofd5.html mysql存储过程详解一.基本介绍1. ...

  9. python编码规范、js编码规范及IDE的检查插件pylint/eslint等

    一.python规范 参考:https://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/的风格规范和语 ...

  10. OCP试题解析之053-17 CONFIGURE CONTROLFILE AUTOBACKUP ON

    17.You configure AUTOBACKUP to ON in an RMAN session. When will RMAN back up the control file? (Choo ...