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

                       B - Is the Information Reliable?

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

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

还是那句话:差分约束条件题目的难点是“怎么找到问题的约束条件”。
这题输入的边有两种格式:
      1. 边长确定,即xi - xj = b; 可以转化成 xi - xj <= b 和 xi - xj >=b (即 xj - xi <= -b).
      2. 边长不定,xi - xj >= 1; 可以转化成 xj - xi <= -1;

da-db>=x;

da-db<=x;

==>da>=db+x;

db>=da-x;

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int n,m,tt;
struct node
{
int x,y,z;
} q[];
int dis[];
void BF()
{
int flag;
memset(dis,,sizeof(dis));
for(int i=; i<=n; i++)
{
flag=;
for(int j=; j<tt; j++)
{
if(dis[q[j].x]<dis[q[j].y]+q[j].z)
{
dis[q[j].x]=dis[q[j].y]+q[j].z;
flag=;
}
}
if(flag==) break;
}
if(flag)
cout<<"Unreliable"<<endl;
else
cout<<"Reliable"<<endl;
return;
}
int main()
{
char ch;
int xx,yy,zz;
while(scanf("%d%d",&n,&m)!=EOF)
{
tt=;
while(m--)
{
getchar();
scanf("%c",&ch);
if(ch=='P')
{
scanf("%d%d%d",&xx,&yy,&zz);
q[tt].x=xx;
q[tt].y=yy;
q[tt++].z=zz;
q[tt].x=yy;
q[tt].y=xx;
q[tt++].z=-zz;
}
else if(ch=='V')
{
scanf("%d%d",&xx,&yy);
q[tt].x=xx;
q[tt].y=yy;
q[tt++].z=;
}
}
BF();
}
return ;
}

POJ2983 Is the Information Reliable?的更多相关文章

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

    Is the Information Reliable? Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 11125   A ...

  2. POJ 之 Is the Information Reliable?

    B - Is the Information Reliable? Time Limit:3000MS     Memory Limit:131072KB     64bit IO Format:%I6 ...

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

    id=2983">[POJ 2983]Is the Information Reliable? (差分约束系统) Is the Information Reliable? Time L ...

  4. Is the Information Reliable? -POJ2983差分约束

    Time Limit: 3000MS Memory Limit: 131072K Description The galaxy war between the Empire Draco and the ...

  5. 【poj2983】 Is the Information Reliable?

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

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

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

  7. POJ 2983-Is the Information Reliable

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

  8. 图论--差分约束--POJ 2983--Is the Information Reliable?

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

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

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

随机推荐

  1. .net 将DLL程序集生成到指定目录中

    .在程序集右键属性 .在程序集属性界面中找到生成事件 在预先生成事件命令行添加: IF NOT EXIST "$(ProjectDir)..\Bin" MD "$(Pro ...

  2. 【MySQL8】 安装后的简单配置(主要解决navicat等客户端登陆报错问题)

    一.navicat等客户端登陆报错的原因 使用mysql,多数我们还是喜欢用可视化的客户端登陆管理的,个人比较喜欢用navicat.一般装好服务器以后,习惯建一个远程的登陆帐号,在mysql8服务器上 ...

  3. java基础---->Runtime类的使用(一)

    这里面我们对java中的Runtime类做一个简单的了解介绍.若不常想到无常和死,虽有绝顶的聪明,照理说也和呆子一样. Runtimeo类的使用 一.得到系统内存的一些信息 @Test public ...

  4. Android 使用tomcat搭建HTTP文件下载服务器

    上一篇: Android 本地搭建Tomcat服务器供真机测试 1.假设需要下载的文件目录是D:\download1(注意这里写了个1,跟后面的名称区分) 2.设置 tomcat 的虚拟目录.在 {t ...

  5. 视频播放效果--video.js播放mp4文件

    HTML5的标签 video 支持的mp4编码为视频编码 H.264 音频AAC 参考网址 http://www.w3school.com.cn/html5/html_5_video.asp 视频格式 ...

  6. sencha touch 监听视图切换动画(animation)

    var animation = this.getLayout().getAnimation(); //添加监听 animation.on({ scope: this, animationend: 'o ...

  7. sencha touch routes(路由) 传递中文参数

    使用路由的时候可以传递参数 如下: index.html#eaterylist/335/61/61/61/B/商户名称 其中6个参数依次是:商户编号/公众账号/微信号/校验号/服务类型/商户名称 因为 ...

  8. nginx 日志文件

    默认日志格式 log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status ...

  9. 使用jetty的continuations实现"服务器推"

    在实际的开发中,我们可能会有这样的场景:许多客户端都连接到服务器端,当有某个客户端的消息的时候,服务器端会主动"推"消息给客户端,手机app的推送是一个典型的场景(IOS的推送都是 ...

  10. 23种设计模式之享元模式(FlyWeight)

    享元模式是一种对象结构型模式,通过运用共享技术,有效地支持大量细粒度的对象.系统只使用少量的对象,而这些对象都很相似,状态变化很小,对象使用次数增多.享元对象能做到共享的关键是区分内部状态和外部状态. ...