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. Luogu P3960 列队 线段树

    题面 线段树入门题. 我们考虑线段树来维护这个矩阵. 首先我们先定n+1棵线段树前n棵维护每行前m-1个同学中没有离队过的同学,还有一棵维护第m列中没有离队过的同学.再定n+1棵线段树前n棵线段树维护 ...

  2. 课堂作业-Bag类的实现

    课堂作业-Bag类的实现 要求: 代码运行在命令行中,路径要体现学号信息,IDEA中,伪代码要体现个人学号信息 参见Bag的UML图,用Java继承BagInterface实现泛型类Bag,并对方法进 ...

  3. 微信小程序 Session 失效

    微信小程序 Session 失效 微信小程序,前端请求后端,中间多了个微信服务器,所以请求的流程就是 页面--微信服务器--目标服务器 这就导致了一个问题 session 每次请求都是一个新的会话 解 ...

  4. Jenkins用HTTP Request Plugin插件进行网站的监控/加探针(运维监控)

    使用的插件: [HTTP Request Plugin] 思路: 说明:只能是网站是否正常打开,而不能是这个网站业务是否正常,如果是后者,则需要写特定的接口进行请求处理. 1.通过插件,发送GET请求 ...

  5. HDU 1864 Brave Game 【组合游戏,SG函数】

    简单取石子游戏,SG函数的简单应用. 有时间将Nim和.SG函数总结一下……暂且搁置. #include <cstdio> #include <cstring> #define ...

  6. 让你的WPF程序在Win7下呈现Win8风格主题

    今天在Win8下使用了一个我之前写的一个WPF程序的时候,发现现在也支持Win8效果了(记得以前的.net 4.0的版本是不支持的).由于WPF的控件是自绘的,并不受系统主题所控制,也就是说.net ...

  7. Express重定向

    var express = require('express'); var app = express(); app.get('/',function(req,res){ res.redirect(' ...

  8. NSLog 输出格式集合

    • %@ 对象 • %d, %i  整数 • %u  无符整形 • %f  浮点/双字 • %x, %X 二进制整数 • %o  八进制整数 • %zu size_t • %p  指针 • %e  浮 ...

  9. Android 卡顿优化 3 布局优化 工具 Hierarchy Viewer

    欲善其事, 先利其器. 分析布局, 就不得不用到Hierarchy Viewer了. 本文工具使用皆以GithubApp的详情界面RepoDetailActivity为例说明. 为了不影响阅读体验, ...

  10. [Java基础] Java对象内存结构

    转载地址:http://www.importnew.com/1305.html 原文于2008年11月13日 发表, 2008年12月18日更新:这里还有一篇关于Java的Sizeof运算符的实用库的 ...