HDU 1814 模板题 2-sat
敲模板做的,不知道怎么就对了,注意一下建边即可···
贴代码:
#include<cstdio>
#include<vector>
using namespace std;
#define N 16005
struct twosat
{
int n;
vector<int> g[N*];
bool vis[N*];
int path[N*];
int c; bool dfs(int x)
{
if(vis[x^]) return false;
if(vis[x]) return true;
vis[x] =true;
path[c++] = x;
for(int i=; i<g[x].size(); ++i)
if(!dfs(g[x][i])) return false;
return true;
}
void init(int n)
{
this->n = n;
for(int i=; i<n*; ++i)
{
g[i].clear();
vis[i] =;
}
} void addEdge(int x,int y)
{
g[x].push_back(y^);
g[y].push_back(x^);
} bool solve()
{
for(int i=; i<*n; i += )
{
if(!vis[i] && !vis[i+])
{
c =;
if(!dfs(i))
{
while(c > ) vis[path[--c]] = false;
if(!dfs(i+)) return false;
}
}
}
return true;
} };
twosat ts;
int main()
{
// freopen("in.c","r",stdin);
int n,m;
while(~scanf("%d%d",&n,&m))
{
ts.init(n);
for(int i=; i<m; ++i)
{
int u,v;
scanf("%d%d",&u,&v);
--u,--v;
ts.addEdge(u,v);
}
if(ts.solve())
{
for(int i=; i<*n; i+=)
printf("%d\n",(ts.vis[i]?i:i^)+);
}
else printf("NIE\n");
}
return ;
}
HDU 1814 模板题 2-sat的更多相关文章
- 【AC自动机】HDU中模板题
[HDU2222] 最纯粹的裸题,错误点详见注释. #include<iostream> #include<cstdio> #include<cstring> #i ...
- HDU 1814 Peaceful Commission / HIT 1917 Peaceful Commission /CJOJ 1288 和平委员会(2-sat模板题)
HDU 1814 Peaceful Commission / HIT 1917 Peaceful Commission /CJOJ 1288 和平委员会(2-sat模板题) Description T ...
- hdu 1814 2-sat 输出字典最小的和任意序列的 模板题
/* 思路:http://blog.csdn.net/string_yi/article/details/12686873 hdu 1814 输出字典序最小的2-sat */ #include< ...
- HDU 2222 AC自动机模板题
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...
- HDU 1251 Trie树模板题
1.HDU 1251 统计难题 Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...
- HDU 4280:Island Transport(ISAP模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:在最西边的点走到最东边的点最大容量. 思路:ISAP模板题,Dinic过不了. #include & ...
- HDU 3065 (AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3065 题目大意:多个模式串,范围是大写字母.匹配串的字符范围是(0~127).问匹配串中含有哪几种模 ...
- HDU 2896 (AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2896 题目大意:多个模式串.多个匹配串.其中串的字符范围是(0~127).问匹配串中含有哪几个模式串 ...
- HDU 2222(AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意:多个模式串.问匹配串中含有多少个模式串.注意模式串有重复,所以要累计重复结果. 解题 ...
随机推荐
- HDU 6106 Classes
Classes 思路:a中包含的元素:只参加a的,只参加a且b的,只参加a且c的,只参加a且b且c的: b中包含的元素:只参加b的,只参加a且b的,只参加b且c的,只参加a且b且c的: c中包含的元素 ...
- C# 中的浅表副本与深表副本
public class Student { public int age; public Student(int age) { this.age = age; } } public class Gr ...
- ISO 8859-1 对照表 (扩展ASCII码表)
1. 0---127 是ASCII码 2.128--255 加了一些特殊符号 DEC OCT HEX BIN Symbol HTML Number HTML Name Description 128 ...
- English trip -- VC(情景课) 8 B job duties 工作职责
Vocabulary focus 核心词汇 She is a receptionist. She answers the phone. She is a cashier She counts mon ...
- LeetCode--119--杨辉三角II
问题描述: 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 3 输出: [1,3,3,1] 进阶: 你可以优化你 ...
- 20170228VBA提取邮件部分信息
Sub 获取OutLook收件箱主题和正文() On Error Resume Next Dim sht As Worksheet Dim olApp As Outlook.Application D ...
- python-day6---运算符
#了解部分#字符串+,*#列表:+,*# l1=[1,2,3]# l2=[4,5]## print(l1+l2)# print(l1*3) #比较运算符# num1=3# num2=1 # print ...
- Error: Chunk.entry was removed. Use hasRuntime()错误解决
Error: Chunk.entry was removed. Use hasRuntime()错误解决 执行如下命令 npm uninstall --save-dev ext ...
- Quartz定时任务和IIS程序池闲置超时时间冲突解决方案
一.问题描述 Bs项目中用Quartz功能执行一个定时任务(每隔5分钟执行一个Job),正常情况,Quartz定时任务会5分钟执行一次,但IIS程序池闲置 超时默认为20分钟,造成的结果是:定时任务只 ...
- File storage location distribution in firmware using binwalk
tool function: Binwalk is a fast, easy to use tool for analyzing, reverse engineering, and extractin ...