裸差分约束。

//#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. Object类概述

    Object:类 Object 是类层次结构的根类.每个类都使用 Object 作为超类.每个类都直接或者间接的继承自Object类. Object类的方法:public int hashCode() ...

  2. case语句

    case语句是多分支选择语句,if语句只有两个分支可供选择,而实际问题中常常需要用到多分支选择结构.例如,学生成绩分类(90分以上为A,--):人口统计分类(按年龄分为老.中.青.少.幼)等.当然这些 ...

  3. vmware workstation LINUX磁盘扩容

    1.edit virtual machine settings -> 选中硬盘->右侧utilities->expand(虚拟机不能存在镜像),输入要扩容到的大小 2.扩容之后进入系 ...

  4. petapoco IsNew

    // Check if a poco represents a new record public bool IsNew(string primaryKeyName, object poco) { v ...

  5. weblogic 优化设置 http://wenku.baidu.com/view/c42e7a5bbe23482fb4da4cf2.html

    引自:http://wenku.baidu.com/view/c42e7a5bbe23482fb4da4cf2.html

  6. centos 6.3 安装 svn

    1. 按照http://ostechnix.wordpress.com/2013/04/30/install-subversion-server-in-centos-6-4-rhel-6-4-scie ...

  7. the philosophy behind of the design of the STL

    The concept of STL is based on a separation of data and operations. The data is managed by container ...

  8. Hadoop伪分布式配置:CentOS6.5(64)+JDK1.7+hadoop2.7.2

    java环境配置 修改环境变量 export JAVA_HOME=/usr/java/jdk1.7.0_79 export PATH=$PATH:$JAVA_HOME/bin export CLASS ...

  9. C++标准转换运算符

    C++类型转换在实际编程中会经常使用,其实,本质上对象的类型用来解释(interpret)对象.因为,每个对象都占据一块内存空间,这块内存空间存放了一段二进制数据.通过标记该对象的类型,告诉如何看待这 ...

  10. ASP.Net将图片以二进制方式存入数据库,并读取

    把图片转换成二进制--把二进制转换成图片 private void button1_Click(object sender, EventArgs e) { string path = this.tex ...