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. E - Hangover(1.4.1)

    Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit cid=1006#sta ...

  2. 浅谈BloomFilter【上】基本概念和实现原理

        在日常生活中.包括在设计计算机软件时,我们常常要推断一个元素是否在一个集合中.     比方在字处理软件中,须要检查一个英语单词是否拼写正确(也就是要推断 它是否在已知的字典中).在 FBI. ...

  3. Android使用LinearViewLayout展示数据

    如果要滚动,使用ScrollView来包裹这个LinearViewLayout. ListView控件,自己带有滚动效果的. BaseAdapter LayoutInflater 其他两种绑定方式 A ...

  4. k8s部署dns

    硬件环境: 两台虚拟机, 10.10.20.203 部署docker.etcd.flannel.kube-apiserver.kube-controller-manager.kube-schedule ...

  5. mysql数据索引

    索引是建立在数据库表中的某些列的上面.因此,在创建索引的时候,应该仔细考虑在哪些列上可以创建索引,在哪些列上不能创建索引.一般来说,应该在这些列上创建索引,例如:在经常需要搜索的列上,可以加快搜索的速 ...

  6. IntelliJ idea——》删除tag

    查看git上所有tag E:\eju_IdeaProjects\house-platform>git tag --11v1. 20181107周三上线 20181120周二上线 v1.0.0 v ...

  7. 解决ajax跨域问题的多种方法

    //第一种方法使用jsonp的方式 <script type="text/javascript" src="http://www.youxiaju.com/js/j ...

  8. android 布局特点

    <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_cont ...

  9. eclipse配置python插件

    eclipse配置python主要可以分为以下几个步骤完成: 1. 安装python,python主要有两个版本,python2和python3,这里安装的是python2.7.主要考虑python使 ...

  10. ASP.NET动态网站制作(14)-- CSS3

    前言:这节课主要讲解CSS之前没有讲到过的知识点以及CSS3的一些内容. 内容: 1.内容参考博文:http://www.cnblogs.com/ruanmou/p/4832214.html. 后记: ...