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 ...
随机推荐
- 【AT91SAM3S】英倍特串口示例工程05-UART中,串口是怎样初始化的
在这个示例工程的main.c文件中,进入main之后,没有发现串口功能的任何配置.直接使用了printf这个东西进行输出.将软件下载到开发板上之后,在电脑端使用串口软件,可以看板子有数据发来.说明这个 ...
- Datagridview 添加checkbox列,并判断Datagridview 中的checkbox列是否被选中
Solution1://In Fill DataGridViewEvent : DataGridViewCheckBoxColumn ChCol = new DataGridViewCheckBoxC ...
- 字符串连接,数字tostring,写入文件
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int x=2410; in ...
- NineOldAndroid开源库简单使用demo
看到很多开源库都使用了这个动画框架,就自己试了一下,果然很强大.把测试代码贴上,方便以后使用 package com.test.animation; import android.animation. ...
- Symfony2 资料篇
http://www.chrisyue.com/symfony2-in-action-day-1.html 由于Symfony2现在还没有很完善的中文文档,所以不想看文档的同学可以直接进行点击上面的链 ...
- finder文件目录跳转快捷键
finder文件目录跳转快捷键 command+shift+G
- 【Tree 3】树形结构数据加载的思考
前面两篇文章,分别介绍了使用递归和非递归算法加载树形结构数据的方式,本篇文章,则是自己闲下来的时候,进行的一点小思考. 一.什么地方会用到树形结构 刚开始一看到这种结构的时候,最先是想到了家谱.家谱就 ...
- 什么是Mbps、Kbps、bps、kb、mb及其换算和区别
Mbps 即 Milionbit pro second(百万位每秒): Kbps 即 Kilobit pro second(千位每秒): bps 即 bit pro second(位每秒): 速度单位 ...
- js事件委托,可以使新添加的元素具有事件(event运用)
miaov视频教程 http://study.163.com/course/courseMain.htm?courseId=231002 <!DOCTYPE html PUBLIC " ...
- delphi Tab Item Badge Value 消息数标记
https://community.embarcadero.com/blogs?view=entry&id=9074 unit TabBadgeFrm; interface uses Syst ...