裸差分约束。

//#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? 差分约束的更多相关文章

  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? 信息可靠吗 (差分约束,spfa)

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

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

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

  4. ●POJ 2983 Is the Information Reliable?

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

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

    题目地址:POJ 2983 题意:有N个车站.给出一些点的精确信息和模糊信息.精确信息给出两点的位置和距离.模糊信息给出两点的位置.但距离大于等于一.试确定是否全部的信息满足条件. 思路:事实上就是让 ...

  6. POJ 3159 Candies 解题报告(差分约束 Dijkstra+优先队列 SPFA+栈)

    原题地址:http://poj.org/problem?id=3159 题意大概是班长发糖果,班里面有不良风气,A希望B的糖果不比自己多C个.班长要满足小朋友的需求,而且要让自己的糖果比snoopy的 ...

  7. POJ 之 Is the Information Reliable?

    B - Is the Information Reliable? Time Limit:3000MS     Memory Limit:131072KB     64bit IO Format:%I6 ...

  8. 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之间的 ...

  9. POJ 3159 Candies(spfa、差分约束)

    Description During the kindergarten days, flymouse was the monitor of his class. Occasionally the he ...

随机推荐

  1. eclipse下新建maven项目

    eclipse下新建maven项目 1.1下载maven安装包 进入Maven官网的下载页面:http://maven.apache.org/download.cgi,如下图所示:\ 选择当前最新版本 ...

  2. struts1 Demo

    每次都会忘记一些东西,反复查找原因,其实struts1很简单,可是不去巩固也很容易忘记并且犯错误.这是一个最简单的登录Demo. 1.建立web工程,引入struts1.2包 2.建package:a ...

  3. Bugtags 介绍视频 - App 测试 · 从未如此简单

    Bugtags 是什么? Bugtags 是移动时代首选 Bug 管理系统,针对不同的使用场景,Bugtags 具有以下强大特性: 移动应用 Bug 管理 Bugtags 可以直接在应用中所见即所得提 ...

  4. thinkphp nginx配置

    安装和配置: http://www.cnblogs.com/Bonker/p/4252588.html  spawn-fcgi 要先安装和启动:(已过时) sudo spawn-fcgi -a -u ...

  5. NSUserDefaults简介及使用

    NSUserDefaults类提供了一个与默认系统进行交互的编程接口.NSUserDefaults对象是用来保存,恢复应用程序相关的偏好设置,配置数据等等.默认系统允许应用程序自定义它的行为去迎合用户 ...

  6. mybatis中当实体类的字段名和表结构中的字段名不一致的时候的处理

    1.在sql语句中使用列的别名 比如:select order_id id,orderNo orderno ,order_price price from order where order_id = ...

  7. 配置ActiveX控件在网页中下载安装

    先检查客户端浏览器是否安装了ActiveX控件,如果没有安装ActiveX,就需要先给浏览器提示下载并允许安装.否则就直接使用该ActiveX控件.我们可以使用CodeBase来满足我们的要求:下面是 ...

  8. [EventBus源码解析] 初探EventBus

    本期blog作为EventBus(以下简称EB)学习的始动篇,主要记载了EB的功能.优点.使用方法,内容基于github上的README.md与HOWTO.md. 何为EventBus EB实现了An ...

  9. eclipse配置javacv0.8

    之前配置了一次javacv,但是忘了做笔记,这次又重新查了一遍资料,很多东西模棱两可,浪费了很多时间,这次配置成功,总结如下,希望能帮到大家. 如不明确,可以联系我.   javacv下载 https ...

  10. 网站接入QQ登录的两种方法

    第一种使用系统自带按钮登录,但是这样会弹出新窗口,不喜欢 //调用QC.Login方法,指定btnId参数将按钮绑定在容器节点中 QC.Login({ //btnId:插入按钮的节点id,必选 btn ...