满汉全席[2-SAT]
对不起我又写了一个板题qvq
和洛谷那道模板题没区别。。。两样菜至少做一样即可
不过注意define和函数的区别!!!
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <complex>
#include <ctime>
#include <vector>
#define mp(x, y) make_pair(x, y)
#define node(x, y) ((x << 1) - y)
using namespace std;
const int N = 2e4 + 5;
struct Edge{
int v, next;
}edge[N];
int head[N], esize;
inline void addedge(int x, int y){
//printf("%d %d\n", x, y);
edge[++esize] = (Edge){y, head[x]}; head[x] = esize;
}
int n, m;
int dfn[N], low[N], tim;
int col[N], colsize, stk[N], top;
bool vis[N];
void tarjan(int x){
stk[++top] = x; vis[x] = 1;
dfn[x] = low[x] = ++tim;
for(int i = head[x], vv; ~i; i = edge[i].next){
vv = edge[i].v;
if(!dfn[vv]) tarjan(vv), low[x] = min(low[x], low[vv]);
else if(vis[vv]) low[x] = min(low[x], dfn[vv]);
}
if(low[x] == dfn[x]){
++colsize;
do{
col[stk[top]] = colsize; vis[stk[top]] = 0;
}while(top && stk[top--] != x);
}
}
inline void clear(){
memset(head, -1, sizeof(head));
memset(col, 0, sizeof(col));
memset(vis, 0, sizeof(vis));
memset(dfn, 0, sizeof(dfn));
memset(low, 0, sizeof(low));
esize = tim = top = colsize = 0;//!!!
}
int main(){
int T; scanf("%d", &T);
while(T--){
clear();
scanf("%d %d\n", &n, &m);
char c1, c2; int x1, x2;
for(int i = 1; i <= m; ++i){
do{c1 = getchar();}while(c1 != 'm' && c1 != 'h');
scanf("%d", &x1);
do{c2 = getchar();}while(c2 != 'm' && c2 != 'h');
scanf("%d", &x2);
int f1 = (c1 == 'm'), f2 = (c2 == 'm');
addedge(node(x1, (f1 ^ 1)), node(x2, f2));
addedge(node(x2, (f2 ^ 1)), node(x1, f1));
//注意define和函数的区别!
//printf("%d %d %d %d %d %d %d\n", x1, f1 ^ 1, x1 << 1, f1 ^ 1, x2, f2, node(x2, f2));
}
for(int i = 1; i <= (n << 1); ++i){
if(!dfn[i]) tarjan(i);
}
bool flag = 1;
for(int i = 1; i <= n; ++i){
// printf("%d %d\n", col[node(i, 0)], col[node(i, 1)]);
if(col[node(i, 0)] == col[node(i, 1)]){
flag = 0; break;
}
}
if(flag) printf("GOOD\n"); else printf("BAD\n");
}
return 0;
}
满汉全席[2-SAT]的更多相关文章
- 多边形碰撞 -- SAT方法
检测凸多边形碰撞的一种简单的方法是SAT(Separating Axis Theorem),即分离轴定理. 原理:将多边形投影到一条向量上,看这两个多边形的投影是否重叠.如果不重叠,则认为这两个多边形 ...
- Bzoj1823 [JSOI2010]满汉全席
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1640 Solved: 798 Description 满汉全席是中国最丰盛的宴客菜肴,有许多种不同的 ...
- Essential C++中文版——满汉全席之外
满汉全席之外 Stanley B. Lippman 所著的C++ Primer 雄踞书坛历久不衰,堪称C++最佳教科书.但是走过十个年头之后,继1237 页的C++ Primer 第3 版,Lippm ...
- C++之路进阶——bzoj1823(满汉全席)
F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser hyxzc Logout 捐赠本站 Notice:由于本OJ建立在 ...
- 【BZOJ1823】 [JSOI2010]满汉全席
Description 满汉全席是中国最丰盛的宴客菜肴,有许多种不同的材料透过满族或是汉族的料理方式,呈现在數量繁多的菜色之中.由于菜色众多而繁杂,只有极少數博学多闻技艺高超的厨师能够做出满汉全席,而 ...
- BZOJ 1823 满汉全席
Description 满汉全席是中国最丰盛的宴客菜肴,有许多种不同的材料透过满族或是汉族的料理方式,呈现在數量繁多的菜色之中.由于菜色众多而繁杂,只有极少數博学多闻技艺高超的厨师能够做出满汉全席,而 ...
- bzoj1823 [JSOI2010]满汉全席(2-SAT)
1823: [JSOI2010]满汉全席 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1246 Solved: 598[Submit][Status ...
- POJ 3678 Katu Puzzle(2 - SAT) - from lanshui_Yang
Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...
- BZOJ 1823: [JSOI2010]满汉全席( 2-sat )
2-sat...假如一个评委喜好的2样中..其中一样没做, 那另一样就一定要做, 这样去建图..然后跑tarjan. 时间复杂度O((n+m)*K) ------------------------- ...
- BZOJ_1823_[JSOI2010]满汉全席_2-sat+tarjan
BZOJ_1823_[JSOI2010]满汉全席_2-sat 题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1823 分析:一道比较容易看出来的 ...
随机推荐
- python集合使用范例的代码
在代码过程中中,将代码过程中比较好的代码段珍藏起来,如下的代码是关于python集合使用范例的代码,希望能对大伙有用. # sets are unordered collections of uniq ...
- 什么是基于风险的测试(RBT)?
基于风险的测试(Risk-based testing) 文/杨学明 一.基于风险的测试起源 基于风险的测试起源,在软件测试领域,基于风险测试最早的是测试大师Boris Beizer<软件测试技术 ...
- NSTimer 不工作 不调用方法
比如,定义一个NSTimer来隔一会调用某个方法,但这时你在拖动textVIew不放手,主线程就被占用了.timer的监听方法就不调用,直到你松手,这时把timer加到 runloop里,就相当于告诉 ...
- GitHub下载克隆clone指定的分支tag代码
需求描述: 这边有很多tag分支版本的代码,我想克隆下载指定版本到我服务器上面 例如:我想下载tag:1.4.1的代码 解决方法: 命令:git clone --branch [tags标签] [gi ...
- 认识多线程中start和run方法的区别?
一.认识多线程中的 start() 和 run() 1.start(): 先来看看Java API中对于该方法的介绍: 使该线程开始执行:Java 虚拟机调用该线程的 run 方法. 结果是两个线程并 ...
- HBase源码实战:ImportTsv
/** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agr ...
- 移动端1px的解决办法之styled
做项目的时候总结了一个styled中解决移动端项目1px像素线的问题,封装了一个函数,大家可以直接使用,很方便. 1 import styled from 'styled-components' co ...
- L2-2 小字辈 (25 分)
本题给定一个庞大家族的家谱,要请你给出最小一辈的名单. 输入格式: 输入在第一行给出家族人口总数 N(不超过 100 000 的正整数) —— 简单起见,我们把家族成员从 1 到 N 编号.随后第二行 ...
- iOS开发基础-九宫格坐标(2)之模型
在iOS开发基础-九宫格(1)中,属性变量 apps 是从plist文件中加载数据的,在 viewDidLoad 方法中的第20行.26行中,直接通过字典的键名来获取相应的信息,使得 ViewCont ...
- win10下ElasticSearch5.5.1与head、Kibana、X-Pack、SQL、IK、PINYIN插件的配置安装
ElasticSearch5.5.1与插件的配置安装 Elasticsearch5.5.1安装: 下载地址https://www.elastic.co/cn/downloads/elasticsear ...