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

Reliabl

给出了 P a  b  w 表示 b在a以北w公里, V a  b 表示 b在a北边,最少1公里,问所有 的条件可不可以全部满足。

由P 可以得到 b - a = w 也就是b - a <= w  &&  a - b <= w ,由 V a  b 得到 b - a >= 1 也就是 a - b <= -1 ;建图,使用最短路,判断是否会有负环。初始dis要全部为0.

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<queue>
  4. #include<algorithm>
  5. #define INF 1e9
  6. using namespace std;
  7. const int maxn=1000+10;
  8. const int maxm=100000*3;
  9. struct Edge
  10. {
  11. int from,to,dist;
  12. Edge(){}
  13. Edge(int f,int t,int d):from(f),to(t),dist(d){}
  14. };
  15. struct BellmanFord
  16. {
  17. int n,m;
  18. int head[maxn],next[maxm];
  19. Edge edges[maxm];
  20. int d[maxn];
  21. int cnt[maxn];
  22. bool inq[maxn];
  23. void init(int n)
  24. {
  25. this->n=n;
  26. m=0;
  27. memset(head,-1,sizeof(head));
  28. }
  29. void AddEdge(int from,int to,int dist)
  30. {
  31. edges[m]=Edge(from,to,dist);
  32. next[m]=head[from];
  33. head[from]=m++;
  34. }
  35. bool bellman_ford()
  36. {
  37. memset(inq,0,sizeof(inq));
  38. memset(cnt,0,sizeof(cnt));
  39. queue<int> Q;
  40. for(int i=0;i<n;i++) d[i]= i==0?0:INF;
  41. Q.push(0);
  42. while(!Q.empty())
  43. {
  44. int u=Q.front(); Q.pop();
  45. inq[u]=false;
  46. for(int i=head[u];i!=-1;i=next[i])
  47. {
  48. Edge &e=edges[i];
  49. if(d[e.to] > d[u]+e.dist)
  50. {
  51. d[e.to] = d[u]+e.dist;
  52. if(!inq[e.to])
  53. {
  54. inq[e.to]=true;
  55. Q.push(e.to);
  56. if(++cnt[e.to]>n) return true;
  57. }
  58. }
  59. }
  60. }
  61. return false;
  62. }
  63. }BF;
  64. int main()
  65. {
  66. int n,m;
  67. while(scanf("%d%d",&n,&m)==2)
  68. {
  69. BF.init(n+1);
  70. while(m--)
  71. {
  72. char s[10];
  73. int u,v,d;
  74. scanf("%s",s);
  75. if(s[0]=='P')
  76. {
  77. scanf("%d%d%d",&u,&v,&d);
  78. BF.AddEdge(u,v,d);
  79. BF.AddEdge(v,u,-d);
  80. }
  81. else if(s[0]=='V')
  82. {
  83. scanf("%d%d",&u,&v);
  84. BF.AddEdge(v,u,-1);
  85. }
  86. }
  87. for(int i=1;i<=n;i++)
  88. BF.AddEdge(0,i,0);
  89. printf("%s\n",BF.bellman_ford()?"Unreliable":"Reliable");
  90. }
  91. return 0;
  92. }

图论--差分约束--POJ 2983--Is the Information Reliable?的更多相关文章

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

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

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

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

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

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

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

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

  5. 图论--差分约束--POJ 3159 Candies

    Language:Default Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 43021   Accep ...

  6. 图论--差分约束--POJ 3169 Layout(超级源汇建图)

    Like everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 < ...

  7. ●POJ 2983 Is the Information Reliable?

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

  8. 图论--差分约束--POJ 1364 King

    Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen p ...

  9. 图论--差分约束--POJ 1201 Intervals

    Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30971 Accepted: 11990 Descripti ...

随机推荐

  1. 家庭版记账本app开发完成

    经过这几天关于android的相关学习,对于家庭版记账本app以及开发结束. 实现的功能为:用户的注册.登录.添加支出账单.添加收入账单.显示所有的该用户的账单情况(收入和支出).生产图表(直观的显示 ...

  2. MTK Android中设置默认时区

    设置默认时区 PRODUCT_PROPERTY_OVERRIDES += \ persist.sys.timezone=Asia/Shanghai\ 注:搜索“persist.sys.timezone ...

  3. 下载SVN项目代码

    1. 到SVN根目录右键选中SVN Checkout...

  4. python 集合(set)和字典(dictionary)的用法解析

    Table of Contents generated with DocToc ditctaionary and set hash 介绍 集合-set 创建 操作和访问集合的元素 子集.超集.相对判断 ...

  5. C# 基础知识系列- 10 反射和泛型(二)

    0. 前言 这篇文章延续<C# 基础知识系列- 5 反射和泛型>,继续介绍C#在反射所开发的功能和做的努力.上一篇文章大概介绍了一下泛型和反射的一些基本内容,主要是通过获取对象的类型,然后 ...

  6. redis list 基本操作

    写在前面的话 本篇笔记写在笔者刚工作时.如有问题,请指教. 简介 list是链表,redis list的应用场景很多,也是Redis 最重要的数据结构之一,比如微博的关注列表,粉丝列表,消息列表等功能 ...

  7. Golang——详解Go语言代码规范

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是Golang专题的第二篇,我们来看看Go的语言规范. 在我们继续今天的内容之前,先来回答一个问题. 有同学在后台问我,为什么说Gola ...

  8. Daily Scrum 1/7/2015

    Process: Zhaoyang: Do some code intergration and test the total feature in the IOS APP. Yandong: Cod ...

  9. codeforces Equalizing by Division (easy version)

    output standard output The only difference between easy and hard versions is the number of elements ...

  10. tensorflow--filter、strides

    最近还在看<TensorFlow 实战Google深度学习框架第二版>这本书,根据第六章里面对于卷基层和池化层的介绍可以发现,在执行 tf.nn.conv2d 和 tf.nn.max_po ...