http://hihocoder.com/problemset/problem/1467

2-sat模板。。。详细的题解请看题目里的提示。

tarjan模板打错again致命伤qwq

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const int N = 103;
const int M = 1003; bool inst[N << 1];
struct node {int nxt, to;} E[M << 1];
int cnt, point[N << 1], dfn[N << 1], low[N << 1], st[N << 1], top = 0, bel[N << 1];
void ins(int u, int v) {E[++cnt] = (node) {point[u], v}; point[u] = cnt;} char A[23], B[23];
int n, m, a, b, ct, tot; void tarjan(int x) {
dfn[x] = low[x] = ++ct;
inst[st[++top] = x] = true;
for (int i = point[x], v = E[i].to; i; v = E[i = E[i].nxt].to)
if (!dfn[v]) tarjan(v), low[x] = min(low[x], low[v]);
else if (inst[v]) low[x] = min(low[x], dfn[v]);
if (dfn[x] == low[x]) {
++tot;
while (st[top] != x) {
inst[st[top]] = false;
bel[st[top--]] = tot;
}
inst[x] = false;
bel[st[top--]] = tot;
}
} int main() {
int T; scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
int doublen = n << 1;
memset(point, 0, sizeof(int) * doublen);
memset(dfn, 0, sizeof(int) * doublen);
ct = cnt = tot = 0;
for (int i = 1; i <= m; ++i) {
scanf("%s%s", A, B);
int lena = strlen(A), lenb = strlen(B);
a = b = 0;
for (int j = 1; j < lena; ++j) a = a * 10 + A[j] - 48;
for (int j = 1; j < lenb; ++j) b = b * 10 + B[j] - 48;
--a; --b;
if (A[0] == 'h') a += n;
if (B[0] == 'h') b += n;
ins((a + n) % doublen, b);
ins((b + n) % doublen, a);
}
for (int i = 0; i < doublen; ++i)
if (!dfn[i])
tarjan(i);
bool flag = false;
for (int i = 0; i < n; ++i)
if (bel[i] == bel[i + n]) {
flag = true;
puts("BAD");
break;
}
if (!flag) puts("GOOD");
}
return 0;
}

【hihoCoder 第133周】2-SAT·hihoCoder音乐节的更多相关文章

  1. 【hihoCoder 第133周】【hihoCoder 1467】2-SAT·hihoCoder音乐节

    http://hihocoder.com/problemset/problem/1467 2-sat模板...详细的题解请看题目里的提示. tarjan模板打错again致命伤qwq #include ...

  2. hihoCoder 第136周 优化延迟(二分答案+手写堆)

    题目1 : 优化延迟 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho编写了一个处理数据包的程序.程序的输入是一个包含N个数据包的序列.每个数据包根据其重要程度不同 ...

  3. HihoCoder第三周与POJ2406:KMP算法总结

    HihoCoder第三周: 输入 第一行一个整数N,表示测试数据组数. 接下来的N*2行,每两行表示一个测试数据.在每一个测试数据中,第一行为模式串,由不超过10^4个大写字母组成,第二行为原串,由不 ...

  4. hiho一下第133周 2-SAT·hihoCoder音乐节(2-SAT)(强连通)

    2-SAT·hihoCoder音乐节 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 hihoCoder音乐节由hihoCoder赞助商大力主办,邀请了众多嘉宾和知名乐队 ...

  5. hihocoder第42周 3*N骨牌覆盖(状态dp+矩阵快速幂)

    http://hihocoder.com/contest/hiho42/problem/1 给定一个n,问我们3*n的矩阵有多少种覆盖的方法 第41周做的骨牌覆盖是2*n的,状态转移方程是dp[i] ...

  6. hiho一下第134周 1468 : 2-SAT·hihoCoder新春晚会

    1468 : 2-SAT·hihoCoder新春晚会 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 hihoCoder新春晚会正在紧张地筹备中.晚会分为上半场和下半场, ...

  7. hihocoder第42周 k*N骨牌覆盖(状态dp+矩阵快速幂)

    上周的3*N的骨牌,因为状态只有8中,所以我们可以手算出状态转移的矩阵 但是这周是k*N,状态矩阵不好手算,都是我们改成用程序自动生成一个状态转移的矩阵就行了,然后用这个矩阵进行快速幂即可 枚举枚举上 ...

  8. hihocoder第220周-一道拧巴的题

    一.220周 题目链接 问题描述 键盘上有N个数字按键,每个按键只能按一次,每次可以按下多个键,请输出所有可能的按键情况. 输入一个整数N(N在1~8之间),输出全部的按键可能.例如:输入3,输出为 ...

  9. hihocoder(第十周)二叉树(前序中序推后续)递推实现

    题目 : 后序遍历 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在参与过了美食节之后,小Hi和小Ho在别的地方又玩耍了一阵子,在这个过程中,小Ho得到了一个非常有意思 ...

随机推荐

  1. LeetCode OJ 111. Minimum Depth of Binary Tree

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  2. could not perform addBatch

    在执行存数据到数据库的操作时,由于增加的ID值小于或等于对应的索引值时会报这个错误

  3. JavaScript跨域总结与解决办法 什么是跨域

    什么是跨域 1.document.domain+iframe的设置 2.动态创建script 3.利用iframe和location.hash 4.window.name实现的跨域数据传输 5.使用H ...

  4. 19个心得 明明白白说Linux下的负载均衡

    [51CTO.com独家特稿]前言:作为一名Linux/unix系统工程师,这几年一直在涉及到对外项目,经手过许多小中型网站的架构,F5.LVS及Nginx接触的都比较多,我想一种比较通俗易懂的语气跟 ...

  5. 如何从Apache官网下载apache

    apache服务器官网地址:http://httpd.apache.org/ linux版本下载比较容易,以windows版本,apache 2.4为例. 点击download 此处随便选一个提供商. ...

  6. myeclipse 调试JSP页面

    http://jingyan.baidu.com/article/636f38bb1ef1aad6b9461048.html

  7. JNI调用问题(部分机型崩溃)

    1.今日测试发现在部分手机上游戏会崩溃,通过logcat日志发现是jni调用问题(我猜测) 错误日志中有如下语句: trying to work around app JNI bugs, but di ...

  8. 查找List中的最大最小值

    以下实例演示了如何使用 Collections 类的 max() 和 min() 方法来获取List中最大最小值: import java.util.*; public class Main { pu ...

  9. HDU ACM 1495 非常可乐(广搜BFS)

    非常可乐 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissi ...

  10. Nape 获取碰撞点加特效

    package { import nape.phys.Body; import nape.shape.Shape; import nape.shape.Circle; import flash.dis ...