12745 Wishmaster

view code#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int N = 200010;
const int M = N<<1;
int _, cas=1, n, m, pre[N], S[N], c;
bool mark[N]; struct edge
{
int u, v, next;
edge() {}
edge(int u, int v, int next):u(u),v(v),next(next) {}
}e[M];
int ecnt = 0; void addedge(int u, int v)
{
if(u<0) u = -u+n;
if(v<0) v = -v+n;
e[ecnt] = edge(u, v, pre[u]);
pre[u] = ecnt++;
} bool dfs(int x)
{
int ano = x>n?x-n:x+n;
if(mark[ano]) return false;
if(mark[x]) return true;
mark[x] = true;
S[c++] = x;
for(int i=pre[x]; ~i; i=e[i].next)
{
int v = e[i].v;
if(!dfs(v)) return false;
}
return 1;
} bool check()
{
for(int i=1; i<=n; i++)
{
if(!mark[i] && !mark[i+n])
{
c = 0;
if(!dfs(i)){
while(c>0) mark[S[--c]] = 0;
if(!dfs(i+n)) return 0;
}
}
}
return 1;
} void solve()
{
scanf("%d%d", &n, &m);
int u, v;
ecnt = 0;
memset(pre, -1, sizeof(pre));
for(int i=0; i<m; i++)
{
scanf("%d%d", &u, &v);
addedge(-u, v);
addedge(-v, u);
} memset(mark, 0, sizeof(mark));
printf("Case %d: ", cas++);
if(check()) puts("Yes");
else puts("No");
} int main()
{
// freopen("in.txt", "r", stdin);
cin>>_;
while(_--) solve();
return 0;
}

uva 12745 Wishmaster(2-sat)的更多相关文章

  1. UVA 10679 I love Strings!!!(AC自己主动机)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. UVA 11488 Hyper Prefix Sets (Trie)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. UVA 1564 - Widget Factory(高斯消元)

    UVA 1564 - Widget Factory 题目链接 题意:n种零件, 给定m个制作时间.每段时间制作k个零件,每种零件有一个制作时间,每段时间用Mon到Sun表示,求每一个零件的制作时间.还 ...

  4. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  5. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  6. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  7. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  8. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

  9. UVA数学入门训练Round1[6]

    UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...

随机推荐

  1. 《Continuous Delivery》 Notes 2: Configuration Management

    What is Configuration Management? Configuration Management refers to the process by which all artifa ...

  2. 编写高性能Javascript代码的若干建议

    多年来,Javascript一直在web应用开发中占据重要的地位,但是很多开发者往往忽视一些性能方面的知识,特别是随着计算机硬件的不断升级,开发者越发觉得Javascript性能优化的好不好对网页的执 ...

  3. Framework7 – 赞!功能齐全的 iOS7 App 前端框架

    Framework7 是一个功能很全的 HTML 框架,用来构建 iOS7 应用程序. Framework7 允许您灵活搭建列表视图(表视图) .你可以让他们作为导航菜单,你可以在列表里面使用图标,输 ...

  4. 每次点击按钮后,判断页面是否已经有该行,没有弹出repeater的一行,并给他赋一个这行附值,没有则跳出

    protected void btnAdd_click(object sender, EventArgs e) { try { //记录第几次追加 pressCount++; typeString.A ...

  5. 奇葩问题:This file could not be checked in because the original version of the file on the server was moved or deleted. A new version of this file has been saved to the server, but your check-in comments were not saved

    "This file could not be checked in because the original version of the file on the server was m ...

  6. [Android]使用AdapterTypeRender对不同类型的item数据到UI的渲染

    以下内容为原创,转载请注明: 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/3992843.html 本文讲的工具均放在AndroidBucket开源 ...

  7. 2015年Java开发岗位面试题归类

    一.Java基础 1. String类为什么是final的. 2. HashMap的源码,实现原理,底层结构. 3. 说说你知道的几个Java集合类:list.set.queue.map实现类咯... ...

  8. 操作系统开发系列—11.ELF格式 ●

    ELF文件的结构如下图所示: ELF文件由4部分组成,分别是ELF头(ELF header).程序头表(Program header table).节(Sections)和节头表(Section he ...

  9. android中实现跑马灯效果以及AutoCompleteTestView与MultiAutoCompleteTextView的学习

    跑马灯效果 1.用过属性的方式实现跑马灯效果 属性:                  android:singleLine="true" 这个属性是设置TextView文本中文字 ...

  10. iOS开发之邓白氏编码申请流程

    要申请企业证书,必须先申请邓白氏编码,在苹果网站有一个免费申请邓白氏编码的链接:https://developer.apple.com/program/enroll/dunsLookupForm.ac ...