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 ...
随机推荐
- Windows下用C++删除磁盘分区信息
做一个能对U盘重新分区的小工具,使用该方法删除U盘中原有的分区表. bool CCesDiskDll::DestroyDisk(unsigned char deviceNumber) { DWORD ...
- 加快phpstorm、rubymine、pycharm系列IDE运行速度的方法
对jetbrains公司出品的IDE均有效,以rubymine为例: 打开C:\Program Files\JetBrains\RubyMine 6.3.3\bin,打开 rubymine.exe.v ...
- 这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script
这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script ##转载注明出处:http://www.cnblogs.com/wade-xu/p/4378224.html ...
- UNIX网络编程-基本API介绍(一)
1.基本结构 大多数套接口函数都需要一个指向套接口地址结构的指针作为参数.每个协议族都定义它自己的套接口地址结构.这些结构的名字均以“sockaddr_”开头,并以对应每个协议族的唯一后缀结束. 1. ...
- Android 获取设备信息 异常
/**获取设备信息 * @param c * @return */ public static void setDeviceInfo(Context c,RequestParams params){ ...
- 53. Minimum Window Substring
Minimum Window Substring Given a string S and a string T, find the minimum window in S which will co ...
- /etc/resolv.conf overwritten. Redhat/Centos
Prevent /etc/resolv.conf from being blown away by RHEL/CentOS after customizing If you are using RHE ...
- Could not load file using Ranorex runtime : General Questions
如果你将编译好的bin文件夹复制到另一个未安装Ranorex程序的电脑上运行遇到如下错误信息 Could not load file or assembly 'Ranorex.Core, Versio ...
- 27、初步探索echarts源码
1.首先发现随笔中凡是和echarts相关的点击率都特别高,于是乎就接着写了echarts因为感觉要转点击率 首先声明我并不是专业做前端的,所以如果有些说得不对的地方,希望前端大神们出来指正 首先发现 ...
- I/O阻塞非阻塞,同步异步
http://www.cnblogs.com/luotianshuai/p/5098408.html "阻塞"与"非阻塞"与"同步"与&qu ...