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. cocos2dx 修改亮度、对比度、色调、饱和度

    废话少说,直接修改CCSprite使用的片面着色器ccShader_PositionTextureColor_noMVP.frag: /* * cocos2d for iPhone: http://w ...

  2. 使用winsw将spring-boot jar包注册成windows服务

    背景:最近的项目中使用spring-boot, https://github.com/kohsuke/winsw/releases <service> <id>YJPSS< ...

  3. 爱她就用python给她画个小心心 ♥(ˆ◡ˆԅ)

    from turtle import * a = Turtle() screensize(400, 300, "blue") setup(width=1300, height=65 ...

  4. 返回固定数据的web服务器

    import socket def handle_client(socket_con): """ 接收来自客户端的请求,并接收请求报文,解析,返回 "" ...

  5. python核心编程2 第八章 练习

    8–2. 循环. 编写一个程序, 让用户输入三个数字: (f)rom, (t)o, 和 (i)ncrement . 以 i为步长, 从 f 计数到 t , 包括 f 和 t . 例如, 如果输入的是 ...

  6. 【操作系统作业-lab4】 linux 多线程编程和调度器

    linux多线程编程 参考:https://blog.csdn.net/weibo1230123/article/details/81410241 https://blog.csdn.net/skyr ...

  7. 通过Samba实现Linux与Windows间的文件共享

    Samba Samba,是用来让Linux系列的操作系统与Windows操作系统的SMB/CIFS(Server Message Block/Common Internet File System)网 ...

  8. C#基础-面向对象-封装

    封装 命名空间 using System; using System.Collections.Generic; using System.Text; namespace ConsoleApp6 { c ...

  9. MARK 一条关于Linux 运维方面个人向收藏网址

    吴钧泽博客 https://wujunze.com/archives.html Linux运维笔记 https://blog.linuxeye.cn/ Linux中文网 http://www.ppze ...

  10. js获取url参数方法

    function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...