B - Is the Information Reliable?

Time Limit:3000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u

Submit Status

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
#include <stdio.h>
#include <string.h> int n, m;
int dis[1003];
int cnt;
struct N
{
int u;
int v;
int w;
}s[200003]; void add(int u, int v, int w )
{
s[cnt].u=u;
s[cnt].v=v;
s[cnt++].w=w;
} void bellman_ford()
{
memset(dis, 0, sizeof(dis));
int i, j;
for(i=1; i<=n; i++)
{
for(j=0; j<cnt; j++) //检查每条边
{
if( dis[s[j].v] > dis[s[j].u] + s[j].w )
dis[s[j].v] = dis[s[j].u]+s[j].w ;
}
}
for(i=0; i<cnt; i++)
{
if(dis[s[i].v] > dis[s[i].u]+s[i].w )
break;
}
if(i<cnt)
printf("Unreliable\n");
else
printf("Reliable\n");
} int main()
{
int i, j;
char ch;
int u, v, w; while(scanf("%d %d%*c", &n, &m)!=EOF)
{
cnt=0;
for(i=0; i<m; i++ )
{
ch=getchar();
while(ch!='P' && ch!='V')
{
ch=getchar();
}
if(ch=='P')
{
scanf("%d %d %d", &u, &v, &w );
add(u, v, -1*w);
add(v, u, w);
}
else
{
scanf("%d %d", &u, &v );
add(u, v, -1 );
}
}
bellman_ford();
}
return 0;
}

POJ 之 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 2983】Is the Information Reliable?(差分约束系统)

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

  7. POJ2983 Is the Information Reliable?

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

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

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

  9. poj 2983Is the Information Reliable?

    http://poj.org/problem?id=2983 #include<cstdio> #include<cstring> #include<algorithm& ...

随机推荐

  1. leetCode 15. 3Sum (3数之和) 解题思路和方法

    3Sum  Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find ...

  2. CSS实现绝对定位居中

    我们经常用margin:0 auto来实现水平居中,而一直认为margin:auto不能实现垂直居中……实际上,实现垂直居中仅需要声明元素高度和下面的CSS: .Absolute-Center { m ...

  3. Hadoop 中的 ArrayWritable

    虽然ArrayWritable不是接口,但貌似必须要子类去extends ArrayWritable,不能直接用ArrayWriable 否则会报下面的错误?(不是很确定) java.lang.Exc ...

  4. 初始化map和list的两种写法

    第一种方法(常用方法): //初始化List List list = new ArrayList(); list.add("string1"); list.add("st ...

  5. linux中的热插拔和mdev机制

    mdev手册(自己翻译的留着看) mdev实现U盘或SD卡的自动挂载 mdev的使用以及mdev.conf的规则配置--busybox linux中的热插拔和mdev机制 关于实现udev/mdev自 ...

  6. 玩转JPA(一)---异常:Repeated column in mapping for entity/should be mapped with insert=&quot;false&quot; update=&quot;fal

    近期用JPA遇到这样一个问题:Repeated column in mapping for entity: com.ketayao.security.entity.main.User column: ...

  7. Ajax主要用来完成哪些工作?

    AJAX 是与服务器交换数据并更新部分网页的艺术,在不重新加载整个页面的情况下. 它使用 JavaScript 在 web 浏览器与 web 服务器之间来发送和接收数据. ajax主要用于在页面内容加 ...

  8. 用PreferenceActivity做一个标准的设置界面

    最后接触到一个任务,做一个工厂设置,在我看来工厂设置不需要多美观,但是一定要方便修改,添加功能,再就是使用方便,我就想到了用PreferenceActivity,android系统的settings就 ...

  9. 第三方-Swift2.0后Alamofire的使用方法

    第一部分,配置项目 首先我们创建一个工程如下图 在此只讲纯手打拉第三方框架的方法 然后把下载的Alamofire解压文件全部放进创建的项目文件夹中,如下图 关键时刻到了哦,集中精神,注意!!! 这个图 ...

  10. 【BZOJ3333】排队计划 树状数组+线段树

    [BZOJ3333]排队计划 Description Input Output Sample Input 6 2 160 163 164 161 167 160 2 3 Sample Output 6 ...