POJ 之 Is the Information Reliable?
Time Limit:3000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64u
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?的更多相关文章
- POJ 2983 Is the Information Reliable?(差分约束系统)
http://poj.org/problem?id=2983 题意:N 个 defense stations,M条消息,消息有精确和模糊之分,若前边为P.则为精确消息,有两个defense stati ...
- ●POJ 2983 Is the Information Reliable?
题链: http://poj.org/problem?id=2983 题解: 差分约束. 1).对于条件(P u v w),不难发现反映到图上就是: $dis[u]-dis[v]=w$,所以添加两条边 ...
- POJ 2983 Is the Information Reliable? 依旧差分约束
http://poj.org/problem?id=2983 题目大意: 星际大战开始了.你购买了情报,需要判断它的准确性.已知地方的根据地在由南向北排成一条直线.P A B X,表示A在B北面距离X ...
- POJ 2983 Is the Information Reliable? 差分约束
裸差分约束. //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #i ...
- POJ 2983 Is the Information Reliable? 信息可靠吗 (差分约束,spfa)
题意:有n个站排成一列,针对每个站的位置与距离关系,现有多个约束条件,约束条件分两种:(1)确定的.明确说明站a距离站b多少个单位距离.(2)不确定的.只知道a在b的左边至少1个单位距离. 根据已知 ...
- 【POJ 2983】Is the Information Reliable?(差分约束系统)
id=2983">[POJ 2983]Is the Information Reliable? (差分约束系统) Is the Information Reliable? Time L ...
- POJ2983 Is the Information Reliable?
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=267#problem/B B - ...
- poj2983--Is the Information Reliable?(差分约束)
Is the Information Reliable? Time Limit: 3000MS Memory Limit: 131072K Total Submissions: 11125 A ...
- poj 2983Is the Information Reliable?
http://poj.org/problem?id=2983 #include<cstdio> #include<cstring> #include<algorithm& ...
随机推荐
- Online advertising术语
做项目发现非常多Online Advertising术语不懂,看代码感觉不那么清晰,如今来总结下遇到的一些术语. ---------------------------- 1. Online Adve ...
- css 用 display: inline-block; 代替 float
浮动可以将两个块级元素浮动在同一水平上.但float的缺点也有很多,还需要其他样式弥补. 早年我使用过 display: inline-block; 但苦于兼容性问题一直没敢全面使用. 近几年主要玩移 ...
- 机器学习10—K-均值聚类学习笔记
机器学习实战之K-Means算法 test10.py #-*- coding:utf-8 import sys sys.path.append("kMeans.py") impor ...
- Jenkins入门(一)
Jenkins就是一个Java Web应用,它主要是干什么呢? 其实很简单: 下载一个jenkins的war包,然后扔到tomcat 的webapps中,启动这个tomcat,访问jenkins应用即 ...
- Mysql----MySQL的mysql_insert_id和LAST_INSERT_ID(转)
本文介绍的是mysql中last_insert_id和mysql_insert_id的区别 1 mysql_insert_id 一.PHP获取MYSQL新插入数据的ID mysql_insert_id ...
- gen_server2 与gen_server的对比
在erlang杀手级应用rabbitmq中,不难发现,有一个gen_server2.erl模块.而在rabbitmq中,gen_server2.erl是对gen_server.erl模块的重写. Ra ...
- C# 中安全代码与不安全代码
C# 中安全代码与不安全代码 P/Invoke 非托管代码需要在unsafe块中书写. using System; using System.Collections.Generic; using Sy ...
- python之开篇---hello world!
(1)前沿 (2)python 简介 (3)python hello world 实现 (4) -------------qq:1327706646 ------------------------- ...
- CentOS 7 mini 试用笔记
CentOS 7 mini 试用笔记 安装过程中,网卡是默认关闭的,要手动打开. 安装好以后,查看IP地址:# ip addr----------------------1: lo: 本地回环2: e ...
- 基于react-native android的新闻app的开发
使用平台:android 代码获取地址:https://github.com/wuwanyu/ReactNative-Android-MovieDemo 项目展示: 结构图: SpalashScree ...