【题目链接】

点击打开链接

【算法】

差分约束系统

【代码】

#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. Insert 语句对 nologging 与 logging表 在不同场景下的优化

    前言 前段时间报表数据库上有条insert sql语句,插入的大量数据,执行非常慢,需要对其进行分析优化. 分析步骤是在:ARCHIVE与NOARCHIVE模式下进行. 测试场景: 分别对表的常规插入 ...

  2. JavaScript关键字

    JavaScript关键字 制作人:全心全意 abstract continue finally instanceof private this boolean default float int p ...

  3. restframework框架之认证

    1. 认证之APIView 在聊APIView之前, 我们先重温一下django2.x的CBV流程 a. 对于django而言, 当浏览器请求到达之后,按照规则首先会经过各大中间件(Middlewar ...

  4. Zoj 3781(构造)

    Zoj 3781(构造) Zoj 3781 As we all know, Coach Gao is a talented chef, because he is able to cook M dis ...

  5. LeetCode 303. Range Sum Query – Immutable

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  6. noip模拟赛 Nephren Ruq Insania

    题目背景 大样例下发链接: https://pan.baidu.com/s/1nuVpRS1 密码: sfxg 注意:本题大样例4的输出文件修改为 https://pan.baidu.com/s/1b ...

  7. codeforces 369B

    #include<stdio.h>//题没读懂,没做出来 int main() {      int n,k,l,r,s,s1,m,a,i; while(scanf("%d%d% ...

  8. codeforces365A

    #include<stdio.h> #include<string.h>//刚做codeforces上的比赛题我都没看懂啊啊啊啊啊啊 int main() { int n,m, ...

  9. Codeforces 621E Wet Shark and Block【dp + 矩阵快速幂】

    题意: 有b个blocks,每个blocks都有n个相同的0~9的数字,如果从第一个block选1,从第二个block选2,那么就构成12,问对于给定的n,b有多少种构成方案使最后模x的余数为k. 分 ...

  10. ZOJ3956 ZJU2017校赛(dp)

    题意:给出n对(h,c) 记  sumh为选出的h的总和  sumc为选出的c的总和 你可以从中选出任意多对(可以不选) 使得  sumh^2-sumh*sumc-sumc^2 最大 输出最大值 输入 ...