【POJ 2983】 Is the information reliable?
【题目链接】
【算法】
差分约束系统,SPFA判负环
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 1010
#define MAXM 200010 struct Edge
{
int to,w,nxt;
} e[MAXM];
int i,n,m,a,b,c,tot;
int dis[MAXN],head[MAXN];
char opt[]; inline void add(int u,int v,int w)
{
tot++;
e[tot] = (Edge){v,w,head[u]};
head[u] = tot;
}
inline bool spfa()
{
int i,cur,v,w;
queue<int> q;
static bool inq[MAXN];
static int cnt[MAXN];
for (i = ; i <= n; i++)
{
dis[i] = ;
q.push(i);
inq[i] = true;
cnt[i] = ;
}
while (!q.empty())
{
cur = q.front();
q.pop();
inq[cur] = false;
for (i = head[cur]; i; i = e[i].nxt)
{
v = e[i].to;
w = e[i].w;
if (dis[cur] + w > dis[v])
{
dis[v] = dis[cur] + w;
if (!inq[v])
{
inq[v] = true;
cnt[v]++;
if (cnt[v] > n) return false;
q.push(v);
}
}
}
}
return true;
}
int main()
{ while (scanf("%d",&n) != EOF && n)
{
tot = ;
for (i = ; i <= n; i++) head[i] = ;
scanf("%d",&m);
while (m--)
{
scanf("%s",&opt);
if (strcmp(opt,"P") == )
{
scanf("%d%d%d",&a,&b,&c);
add(b,a,c);
add(a,b,-c);
} else
{
scanf("%d%d",&a,&b);
add(b,a,);
}
}
if (spfa()) printf("Reliable\n");
else printf("Unreliable\n");
} return ; }
【POJ 2983】 Is the information reliable?的更多相关文章
- 【POJ 2983】Is the Information Reliable?(差分约束系统)
id=2983">[POJ 2983]Is the Information Reliable? (差分约束系统) Is the Information Reliable? Time L ...
- POJ 2983:Is the Information Reliable?(差分约束)
题目大意:有n个点在一条直线上,有两类关系:P(x,y,v)表示x在y北边v距离处,V(x,y)表示x在y北边至少1距离出,给出一些这样的关系,判断是否有矛盾. 分析: 差分约束模板题,约束条件P:a ...
- 【POJ 3140】 Contestants Division(树型dp)
id=3140">[POJ 3140] Contestants Division(树型dp) Time Limit: 2000MS Memory Limit: 65536K Tot ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
随机推荐
- 零基础入门学习Python(3)--小插曲之变量和字符串
前言 小甲鱼说,在对前边的小游戏改善前,先了解下,Python中的变量与字符串. 主要内容 变量 变量名就像我们现实社会的名字,把一个值赋值给一个名字时,Ta会存储在内存中,称之为变量(variabl ...
- php7 安装swoole扩展
昨天无意中看到一篇关于直播的视频教程 里面讲到了swoole,对于这个东西我相信大家(接近1年phper)都是听过它,但没有真正去用它,当然也是不知道如何使用(me too). 此处总结一下(借鉴了几 ...
- 还在为百度网盘下载速度太慢烦恼?chrome浏览器插件帮你解决!
百度网盘已然成为分享型网盘中一家独大的“大佬”了.时代就是这样不管你喜不喜欢,上网总会遇到些百度网盘共享的文件需要下载.然而,百度网盘对免费用户的限速已经到了“感人”的地步了,常常十多KB/秒的速度真 ...
- ACdream 1063 字典树
ACdream 1063 字典树 平衡树 神奇的cxlove有一颗平衡树,其树之神奇无法用语言来描述 OrzOrz. 这棵树支持3种操作: 1.加入一个数到树中,维护平衡树的合法性: 2.给一个数X, ...
- Fiddler抓取https相关设置
转自:https://www.cnblogs.com/joshua317/p/8670923.html 很多使用fiddler抓包,对于http来说不需太多纠结,随便设置下就能用,但是抓取https就 ...
- myeclipse通过数据表生成jpa或hibernate实体---https://blog.csdn.net/partner4java/article/details/8560289
myeclipse通过数据表生成jpa或hibernate实体-----https://blog.csdn.net/partner4java/article/details/8560289
- poj3440--Coin Toss(几何上的概率)
Coin Toss Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3946 Accepted: 1076 Descrip ...
- I - Balancing Act POJ - 1655
Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any node from the t ...
- [bzoj1717][Usaco2006 Dec]Milk Patterns 产奶的模式_后缀数组_二分答案
Milk Patterns 产奶的模式 bzoj-1717 Usaco-2006 Dec 题目大意:给定一个字符串,求最长的至少出现了$k$次的子串长度. 注释:$1\le n\le 2\cdot 1 ...
- Python安装与基本数据类型
人生苦短,我选Python. Python比其他的语言来说真的简洁多了,很多时候想做的东西都有对应的模块可以导入,平时玩点小东西真心不错. 首先讲一下安装,其实没什么好讲的,点点点点点,完事. 这里的 ...