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

Solution:

  还是差分约束判断可行性。。。

  我们依然罗列出约束条件(可行性我直接当做求最小值来做):

    1、$s[v]-s[u]=c,s[u]-s[v]=c$,所以建边$w[u,v]=w[v,u]=c$(注意是双向的,因为等于是个对于两边都成立的约束条件

    2、$s[v]-s[u]>0$,即$s[v]-s[u]\geq 1$,所以建边$w[u,v]=1$

  记得新建一个源点,连向各点$w[1,i]=0,\;i\in 1\rightarrow n$,以保证图联通。

  然后跑一遍最长路,判断一下有无环输出就好了。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#pragma GCC optimize(2)
#define il inline
#define For(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
using namespace std;
const int N=,M=,inf=;
int h[M],to[N],net[N],w[N],cnt,dis[M],tot[M],n,m;
bool vis[M]; il void add(int u,int v,int c){to[++cnt]=v,net[cnt]=h[u],h[u]=cnt,w[cnt]=c;} il void gi(int &a){
a=;char x=getchar();bool f=;
while((x<''||x>'')&&x!='-')x=getchar();
if(x=='-')x=getchar(),f=;
while(x>=''&&x<='')a=(a<<)+(a<<)+x-,x=getchar();
} il bool spfa(){
queue<int>q;
dis[]=;q.push();tot[]++;
while(!q.empty()){
int u=q.front();q.pop();vis[u]=;
for(int i=h[u];i;i=net[i])
if(dis[to[i]]<dis[u]+w[i]){
dis[to[i]]=dis[u]+w[i];
if(!vis[to[i]]){
if(++tot[to[i]]>n)return ;
q.push(to[i]),vis[to[i]]=;
}
}
}
return ;
} int main(){
while(~scanf("%d%d",&n,&m)){
char s[];
cnt=;
memset(dis,-0x3f,sizeof(int)*(n+));
memset(vis,,sizeof(int)*(n+));
memset(tot,,sizeof(int)*(n+));
memset(h,,sizeof(h));
int u,v,c;
while(m--){
scanf("%s",s);
gi(u),gi(v);
if(s[]=='P'){
gi(c);
add(v,u,-c);add(u,v,c);
}
else add(u,v,);
}
For(i,,n) add(,i,);
if(spfa())puts("Reliable");
else puts("Unreliable");
}
return ;
}

POJ 2983-Is the Information Reliable的更多相关文章

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

    http://poj.org/problem?id=2983 题意:N 个 defense stations,M条消息,消息有精确和模糊之分,若前边为P.则为精确消息,有两个defense stati ...

  2. ●POJ 2983 Is the Information Reliable?

    题链: http://poj.org/problem?id=2983 题解: 差分约束. 1).对于条件(P u v w),不难发现反映到图上就是: $dis[u]-dis[v]=w$,所以添加两条边 ...

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

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

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

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

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

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

  6. POJ 之 Is the Information Reliable?

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

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

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

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

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

  9. POJ2983 Is the Information Reliable?

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

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

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

随机推荐

  1. java基础语法:非法修饰符组合 abstract

    abstract 与 final :abstract 是需要被继承以实现的,final却说你不能被修改,逻辑错误 abstract 与  private:同样的abstract 需要被子类实现,但pr ...

  2. iOS 远程通知(Remote Notification)和本地通知(Local Notification)

    ios通知分为远程通知和本地通知,远程通知需要连接网络,本地通知是不需要的,不管用户是打开应用还是关闭应用,我们的通知都会发出,并被客户端收到 我们使用远程通知主要是随时更新最新的数据给用户,使用本地 ...

  3. json对象与字符串相互转换

    JSON 语法 JSON 语法规则 在 JS 语言中,一切都是对象.因此,任何支持的类型都可以通过 JSON 来表示,例如字符串.数字.对象.数组等.但是对象和数组是比较特殊且常用的两种类型: 对象表 ...

  4. kruscal 模板

    /* Kruskal模板 */ struct edge{ int from; int to; int next; int value; bool operator<(const edge a) ...

  5. 在 publicId 和 systemId 之间需要有空格。

    spring  applicationContext_datasource.xml中约束错误 org.springframework.beans.factory.xml.XmlBeanDefiniti ...

  6. Mybatis基础进阶学习2

    Mybatis基础进阶学习2 1.测试基本结构 2.三个POJO package com.pojo; import java.io.Serializable; import java.util.Dat ...

  7. Linux - 用户环境变量的查看与设置

    1. 查看当前有哪些环境变量 直接输入命令:env 2. 设置用户环境变量 输入命令:vim ~/.bash_profile,打开文件,输入如下内容: 范例(设置maven环境变量): export ...

  8. keepalived实现nginx的高可用

    1.使用yum安装keepalived yum install keepalived -y 2.修改配置文件keepalived.conf 主服务器配置文件 global_defs { router_ ...

  9. Spring Security 简介

    本文引自:https://blog.csdn.net/xlecho/article/details/80026527 在 Web 应用开发中,安全一直是非常重要的一个方面.安全虽然属于应用的非功能性需 ...

  10. 学习python第十一天,函数3 函数的序列化和反序列化

    我们把变量从内存中变成可存储或传输的过程称之为序列化,序列化之后,就可以把序列化后的内容写入磁盘,或者通过网络传输到别的机器上. 反过来,把变量内容从序列化的对象重新读到内存里称之为反序列化,即unp ...