Time Limit: 3000MS Memory Limit: 131072K

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

Source

POJ Monthly–2006.08.27, Dagger

题意:有n个防御塔和m个情报,判断这些情报是不是可信,情报有两种:(1):P u v w 表示u在v的w光年处 。(2):V u v 表示u在v北的一光年之外(包括一光年)

思路:Dis[i]表示i在源点北面Dis[i]光年,所以对于(1):P uv w 可以表示为Dis[u]-Dis[v]=w,所以Dis[u]-Dis[v]>=w且Dis[v]-Dis[u]>=-w,对于(2): V u v 可以表示为Dis[u]-Dis[v]>=1,所以建立图,跑最长路,判断是不是有矛盾即正环,我用的

SPFA,要判断自环。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <string>
#include <vector>
#include <stack>
#include <iostream>
#include <algorithm> using namespace std; const int INF = 0x3f3f3f3f; const int MaxN = 1100; const int MaxM = 100100; typedef struct node
{
int v,w,next;
}Line; Line Li[MaxM*2]; int Head[MaxN],top; int Dis[MaxN],Du[MaxN]; bool vis[MaxN]; int n,m; void AddEdge(int u,int v,int w)
{
Li[top].v = v ; Li[top].w = w; Li[top].next = Head[u]; Head[u] = top++;
} bool SPFA()
{
queue<int>Q; for(int i=1;i<=n;i++)//相当于有一个超级源点
{
Dis[i] = 0; vis[i]=true; Du[i]=1; Q.push(i);
} while(!Q.empty())
{
int u = Q.front(); Q.pop(); if(Du[u]>n)//有矛盾
{
return false;
}
for(int i = Head[u];i!=-1;i = Li[i].next)
{
int v = Li[i].v; if(Dis[v]<Dis[u]+Li[i].w)
{
Dis[v] = Dis[u]+Li[i].w; if(!vis[v])
{
Q.push(v);
vis[v] = true;
Du[v]++;
}
}
}
vis[u]=false;
}
return true;
} int main()
{
char Op[5]; int u,v,w; while(~scanf("%d %d",&n,&m))
{
memset(Head,-1,sizeof(Head)); top = 0; bool flag=false; for(int i=1;i<=m;i++)
{
scanf("%s",Op); if(Op[0]=='P')
{
scanf("%d %d %d",&u,&v,&w); if(u==v&&w!=0)//自环
{
flag=true;
} AddEdge(u,v,w); AddEdge(v,u,-w);
}
else
{
scanf("%d %d",&u,&v); if(u==v)
{
flag=true;
} AddEdge(u,v,1);
}
}
if(flag||!SPFA())
{
printf("Unreliable\n");
}
else
{
printf("Reliable\n");
}
}
return 0;
}

Is the Information Reliable? -POJ2983差分约束的更多相关文章

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

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

  2. POJ 2983:Is the Information Reliable?(差分约束)

    题目大意:有n个点在一条直线上,有两类关系:P(x,y,v)表示x在y北边v距离处,V(x,y)表示x在y北边至少1距离出,给出一些这样的关系,判断是否有矛盾. 分析: 差分约束模板题,约束条件P:a ...

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

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

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

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

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

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

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

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

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

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

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

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

  9. 【poj2983】 Is the Information Reliable?

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

随机推荐

  1. vert.x学习(五),用StaticHandler来处理静态文件

    做web开发,css.js.图片等静态资源是必不可少的,那么vert.x又是怎么来加载这些静态资源呢.请看StaticHandler 编写HelloStaticResource.java packag ...

  2. php类和对象

    <?php 1. 类的简单格式: [修饰符] class 类名{ [成员属性] //成员属性,也叫成员变量 [成员方法] //成员方法:也叫成员函数 } 类的完整格式: [修饰符] class ...

  3. WebView 一直展示加载中。。。

    webview加载html5页面总是一直在加载中,加载很慢或干脆加载不出来, 听浏览器的大牛说可能是 js导致的,尝试在onpause里加入mWebView.pauseTimers(), onResu ...

  4. vim - char code and charset

    In normal mode, type ga to display the decimal and hex values for the character under the cursor, or ...

  5. mysql 工具箱

    创建测试数据 存储过程: delimiter // create procedure sp_generate_data() begin ; do set @created_time := date_a ...

  6. Android Studio中获取查看签名SHA1证书指纹数据或MD5的方法

    原来在Eclipse中获取SHA1或者MD5,在IDE界面上就可以查找到. 切换到Android Studio后,如何查看呢?找了半天没找到.那就老办法命令行. 第一步.打开Android Studi ...

  7. js数组方法扩展

    /** * Created by Administrator on 2016/9/1. */ //数组去重 Array.prototype.unique = function(){ this.sort ...

  8. jquery 选择器(name,属性,元素)大全

    jQuery 选择器大体上可分为:基本选择器.层次选择器.过滤选择器.表单选择器. 其中过滤选择器可以分为:简单过滤选择器.内容过滤选择器.可见性过滤选择器.属性过滤选择器.子元素过滤选择器.表单对象 ...

  9. html标签分两种:块状元素和内联元素

      块状元素一般是其它元素的容器,可以容纳内联元素和其它块状元素,独占一行,宽度和高度起作用.如div,p等标签属于块状元素.     内联元素只能容纳文本和其它内联元素,可与其它内联元素位于同一行, ...

  10. background-image小解

    body { width: 600px; height: 500px; border: 10px solid #789; margin: 10px 100px; padding: 40px; back ...