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. ES6 extends继承及super使用读书笔记

    extends 继承 extends 实现子类的继承 super() 表示父类的构造函数, 子类必须在 constructor中调用父类的方法,负责会报错. 子类的 this 是父类构造出来的, 再在 ...

  2. [JZOJ] 5905. 黑暗之魂(darksoul)

    基环树直径裸题 分别在子树做DP,环上做DP,环上可以用单调队列优化到\(O(n)\) 写起来很麻烦 #include<algorithm> #include<iostream> ...

  3. linux mysql5.7 安装、 开机启动

    一.安装 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz h ...

  4. Linux终端显示控制字符

    在Linux中, 我们时常要将一个命令的输出作为另外一个命令的输入进行下一步处理操作. 有时, 如果一个命令的输出中有不可见的控制字符时, 有可能会导致后续操作出错. 而这些控制字符很可能是不可打印的 ...

  5. 用php读取xml数据

    parser是php内置的一个用来处理xml的解析器,它的工作由三个事件组成:起始标签. 读取数据.结束标签. 也就是说在对xml进行处理的时候每当遇到起始标签.数据和结束标签的时候函数会做相应的动作 ...

  6. Redis在windows下安装过程(转)

    (转)原文:http://www.cnblogs.com/M-LittleBird/p/5902850.html 要使redis在PHP下运行, 需在PHP文件下的ext扩展文件夹中添加扩展文件 ph ...

  7. JAVA 扫雷 程序

    文件列表 2.主程序入口 3.1部分源代码 package MineSweeper; import java.awt.BorderLayout; import java.awt.Font; impor ...

  8. C++基础 inline 默认参数 函数占位参数 函数重载

    1. inline内联函数 内联函数用于替换宏, 实例: 其中宏和 ++ 连用有副作用. #include "iostream" using namespace std; #def ...

  9. POJ3682 概率DP

    King Arthur's Birthday Celebration Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3575 ...

  10. [Hdu1166]敌兵布阵(CQD分治)

    CQQ分治 Code #include <cstdio> #include <cstring> #define N 50010 struct info{ int x,p,v; ...