【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 ...
随机推荐
- [Python3网络爬虫开发实战] 1.9.5-Scrapyrt的安装
Scrapyrt为Scrapy提供了一个调度的HTTP接口,有了它,我们就不需要再执行Scrapy命令而是通过请求一个HTTP接口来调度Scrapy任务了.Scrapyrt比Scrapyd更轻量,如果 ...
- js 技巧 (三)
//无模式的提示框 function modelessAlert(Msg) { window.showModelessDialog("javascript:alert("&q ...
- linux命令 dig-域名查询工具
博主推荐:更多网络测试相关命令关注 网络测试 收藏linux命令大全 dig命令是常用的域名查询工具,可以用来测试域名系统工作是否正常. 语法 dig(选项)(参数) 选项 @<服务器地址&g ...
- win10下安装psql9,后无法访问数据库引擎
1.修改安装文件兼容性,并启动安装 2.安装后 修改psql control center快捷方式的启动文件兼容性 3.修改 start workgroup engine 快捷方式的启动文件兼容性 一 ...
- Python关于函数作为返回值的理解(3分钟就看完了)
话不多说,直接看例子,上代码: def line_conf(): def line(x): return 2 * x + 1 return line #return a function object ...
- 慕课笔记利用css进行布局【三列布局】
三个div中间自适应,两侧固定大小 <html> <head> <title>三列布局</title> <style type="tex ...
- NYOJ-476谁是英雄,分解质因子求约数个数!
谁是英雄 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 十个数学家(编号0-9)乘气球飞行在太平洋上空.当横越赤道时,他们决定庆祝一下这一壮举.于是他们开了一瓶香槟.不 ...
- 【最大流】Escape
https://www.bnuoj.com/v3/contest_show.php?cid=9149#problem/F [题意] 给定n个人和m个星球,每个人可以匹配某些星球,每个星球有一定的容量限 ...
- hdu 4033 状态压缩枚举
/* 看别人的的思路 搜索搜不出来我太挫了 状态压缩枚举+好的位置 */ #include<stdio.h> #include<string.h> #define N 20 i ...
- MySQL数据库:SQL语句基础、库操作、表操作、数据类型、约束条件、表之间的关系
数据库相关概念: 1. 数据库服务器:运行数据库管理软件的计算机 2. 数据库管理软件:MySQL.Oracle.db2.slqserver 3. 库:文件夹,用来组织文件/表 4. 表:文件(类似于 ...