【题目链接】

点击打开链接

【算法】

差分约束系统

【代码】

#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 205 struct Edge
{
int to,w,nxt;
} e[MAXN];
int n,m,i,a,b,d,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++)
{
inq[i] = true;
q.push(i);
dis[i] = ;
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])
{
cnt[v]++;
if (cnt[v] > n + ) return false;
inq[v] = true;
q.push(v);
}
}
}
}
return true;
} int main() { while (scanf("%d",&n) != EOF && n)
{
tot = ;
for (i = ; i <= n; i++) head[i] = ;
scanf("%d",&m);
for (i = ; i <= m; i++)
{
scanf("%d%d%s%d",&a,&b,&opt,&d);
if (strcmp(opt,"lt") == ) add(a-,a+b,d-);
else add(a+b,a-,-d-);
}
if (!spfa()) printf("successful conspiracy\n");
else printf("lamentable kingdom\n");
}
return ; }

【POJ 1364】 King的更多相关文章

  1. 【POJ 2942】Knights of the Round Table(双联通分量+染色判奇环)

    [POJ 2942]Knights of the Round Table(双联通分量+染色判奇环) Time Limit: 7000MS   Memory Limit: 65536K Total Su ...

  2. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  3. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  4. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  5. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  6. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  7. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  8. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  9. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

随机推荐

  1. linux中PHP安装扩展包(mongodb为例)

    相对于windows中的PHP扩展,只需要在下载相应的dll资源,并且添加配置在php.ini之后即可. 但是在linux安装扩展时,需要进行编译安装. 这里以lnmp一键安装包为例(php.ini位 ...

  2. vscode 解决符号无法识别的问题

    一开始浏览代码出现了下面这个问题, __attribute__ 标记为红色,符号无法识别,下面还出现了很多提示需要加 ), } 等符号,虽然编译没问题,但是看着红色标记和一堆提示真是要逼死强迫症. 既 ...

  3. Not so Mobile (针对递归输入的函数)

      Before being an ubiquous communications gadget, a mobile was just a structure made of strings and ...

  4. jquery源码——noConflict实现

    实现方式很简单:在初始化的时候,记录当前全局中jQuery和$两个变量的的值,用_jQuery和_$分别存放,调用noConflict方法时,使用_jQuery和_$分别恢复对应的值,并且返回jQue ...

  5. 【02】HTML5与CSS3基础教程(第8版)(全)

    [02]HTML5与CSS3基础教程(第8版)(全)   共392页.   (魔芋:大体上扫了一遍.没有什么新东西,都是入门的一些基础知识.) 已看完.       [美]elizabeth cast ...

  6. 使用vim正则表达式删除C/C++注释 及 两种注释风格替换

    /*对于C风格的注释可以使用如下命令*/ :%s/\_s*\/\*\(\S\|\_s\)\{-}\*\///g //对于C++风格注释 :%s/\/\/.*//g /*...*/ -> //.. ...

  7. redis持久化机制【十三】

    一.Redis提供了哪些持久化机制: redis的高性能是因为其所有数据都存在了内存中 ,为了使redis在重启之后数据仍然不丢失,需要将数据同步到硬盘中,这一过程就是持久化. redis支持两种方式 ...

  8. Linux下汇编语言学习笔记26 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  9. 在fragment中获取activity的组件

    在fragment中使用getActivity()即可获取activity的引用

  10. Java电商项目-6.实现门户首页数据展示_Redis数据缓存

    目录 项目的Github地址 需求介绍 搭建Redis集群环境 下面先描述单机版redis的安装 下面将进行Redis3主3从集群环境搭建 基于SOA架构, 创建门户ashop-portal-web门 ...