POJ 2983 Is the Information Reliable? 差分约束
裸差分约束。
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define pb(a) push(a)
#define INF 0x1f1f1f1f
#define lson idx<<1,l,mid
#define rson idx<<1|1,mid+1,r
#define PI 3.1415926535898
template<class T> T min(const T& a,const T& b,const T& c) {
return min(min(a,b),min(a,c));
}
template<class T> T max(const T& a,const T& b,const T& c) {
return max(max(a,b),max(a,c));
}
void debug() {
#ifdef ONLINE_JUDGE
#else freopen("data.in","r",stdin);
// freopen("d:\\out1.txt","w",stdout);
#endif
}
int getch() {
int ch;
while((ch=getchar())!=EOF) {
if(ch!=' '&&ch!='\n')return ch;
}
return EOF;
} struct Edge
{
int from, to, dist;
};
const int maxn = ;
int n;
vector<int> g[maxn];
vector<Edge> edge; void Init()
{
for(int i = ; i <= n; i++)
g[i].clear();
edge.clear();
}
void AddEdge(int u, int v, int w)
{
edge.push_back((Edge){u, v, w});
g[u].push_back(edge.size() - );
} int inq[maxn];
int cnt[maxn];
int d[maxn]; bool SPFA()
{
queue<int> q;
for(int i=; i<=n; i++)
{
inq[i] = true;
cnt[i] = ;
d[i] = ;
q.push(i);
}
while(!q.empty())
{
int u = q.front(); q.pop();
inq[u] = false;
for(int i=; i < g[u].size(); i++)
{
//cout<<g[u][i]<<endl;
Edge &e = edge[ g[u][i] ];
//cout<<" "<<e.from<<" "<<e.to<<" "<<e.dist<<endl;
if(d[e.to] < d[u] + e.dist)
{
d[e.to] = d[u] + e.dist;
inq[e.to] = true;
if(++cnt[e.to] > n) return ;
q.push(e.to);
}
}
}
return ;
} int main()
{
debug();
int m;
while(scanf("%d%d", &n, &m) != EOF)
{
Init();
for(int i = ; i <= m; i++)
{
char op = getch();
if(op == 'P')
{
int u,v,x;
scanf("%d%d%d", &u, &v, &x);
AddEdge(u,v,x);
AddEdge(v,u,-x);
}else
{
int u,v;
scanf("%d%d", &u, &v);
AddEdge(v,u,);
}
}
//cout<<edge.size()<<endl;
// for(int i=0; i<=n; i++)
// cout<<g[i].size()<<endl;
int ans = SPFA();
printf("%s\n", ans?"Reliable":"Unreliable");
}
return ;
}
POJ 2983 Is the Information Reliable? 差分约束的更多相关文章
- 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? 信息可靠吗 (差分约束,spfa)
题意:有n个站排成一列,针对每个站的位置与距离关系,现有多个约束条件,约束条件分两种:(1)确定的.明确说明站a距离站b多少个单位距离.(2)不确定的.只知道a在b的左边至少1个单位距离. 根据已知 ...
- 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?(差分约束系统)
题目地址:POJ 2983 题意:有N个车站.给出一些点的精确信息和模糊信息.精确信息给出两点的位置和距离.模糊信息给出两点的位置.但距离大于等于一.试确定是否全部的信息满足条件. 思路:事实上就是让 ...
- POJ 3159 Candies 解题报告(差分约束 Dijkstra+优先队列 SPFA+栈)
原题地址:http://poj.org/problem?id=3159 题意大概是班长发糖果,班里面有不良风气,A希望B的糖果不比自己多C个.班长要满足小朋友的需求,而且要让自己的糖果比snoopy的 ...
- POJ 之 Is the Information Reliable?
B - Is the Information Reliable? Time Limit:3000MS Memory Limit:131072KB 64bit IO Format:%I6 ...
- Is the Information Reliable?(差分约束系统)
http://poj.org/problem?id=2983 题意:给出M条信息,判断这些信息的正确性.(1)V A B :表示A,B之间的距离>=1; (2)P A B X :表示A B之间的 ...
- POJ 3159 Candies(spfa、差分约束)
Description During the kindergarten days, flymouse was the monitor of his class. Occasionally the he ...
随机推荐
- Eclipse下新建Maven项目、自动打依赖jar包
当我们无法从本地仓库找到需要的构件的时候,就会从远程仓库下载构件至本地仓库.一般地,对于每个人来说,书房只有一个,但外面的书店有很多,类似第,对于Maven来说,每个用户只有一个本地仓库,但可以配置访 ...
- Mysql 自定义HASH索引带来的巨大性能提升----[真相篇]
推倒重来 俗话说no zuo no die why you try,这时候我又忍不住zuo了,吭哧吭哧的把解决过程发上博客,向全世界宣布,哥又搞定个难题. 剧情的发展往往是看起来主角完全掌握了局势的情 ...
- JQuery Placeholder - Input提示信息
JQuery Placeholder Placeholder属性是HTML5为Input添加的,在Input上提供一个占位符,文字形式展示输入文字预期值的提示信息. 如: 需要使用:placehold ...
- logstash 因为jdk版本不对造成索引时间戳失败
版本 logstash 1.5.0 RC2 JDK 1.7.15 Logstash推荐使用JDK 1.7.75 每次启动都是会有部分的数据无法替换日志中的时间戳,导致日志时间戳被认定为当前读取时间. ...
- oracle11g rac asm存储数据迁移
OS:rh6.4 ORACLE 11g RAC ASM OCR和VOTING DISK在crs磁盘组,控制文件.数据文件.参数文件在DATA组. 1.备份数据库 RUN {ALLOCATE CHANN ...
- Python基础篇【第8篇】: Socket编程 (一)
Python Socket 官方关于 Socket 的函数请看 http://docs.python.org/library/socket.html 一.socket介绍 在网络编程中的一个基本组件就 ...
- day7-socket
socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,应用程序通常通过"套接字"向网络发出请求或者应答网络请求. socket起源于Un ...
- HDU5900
http://acm.hdu.edu.cn/showproblem.php?pid=5900 就是给出两行数字,每行有若干的数,如果相邻的两个数字的最大公约数不是1 的话拟具可以把这两数删除,并且把第 ...
- C# IO
在.NET框架中进行的所有IO操作都要用到流(Stream). System.IO命名空间中包含许多IO相关的类,C#文件读写的类几乎都在其中,下面对其进行详细介绍. 主要类列表: 类 说明 Bina ...
- eclipse配置javacv0.8
之前配置了一次javacv,但是忘了做笔记,这次又重新查了一遍资料,很多东西模棱两可,浪费了很多时间,这次配置成功,总结如下,希望能帮到大家. 如不明确,可以联系我. javacv下载 https ...