题目大意:给你 m 个式子, 问你最少再添加多少式子能使没有任何一种赋值方式使全部的式子为真。 并且在你给的式子中不能有非。

思路:根据题目给的m个式子可以建出2-Sat的图, 现在问你最少加多少个边使得2-Sat不成立, 我们可以发现我们给出的式子肯定是 a | a

的形式, 在题目中没有 ~p | ~q这种形式必定无解, 否则最多增加2式子就能完成, 我们枚举a, 取check如果所有都不行就输出2。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, m;
bool flag;
int scc[N], stk[N], dfn[N], low[N], tot, cnt, idx;
bool in[N];
vector<int> G[N]; void tarjan(int u) {
dfn[u] = low[u] = ++idx;
stk[++tot] = u, in[u] = true;
for(int v : G[u]) {
if(!dfn[v]) tarjan(v), low[u] = min(low[u], low[v]);
else if(in[v]) low[u] = min(low[u], dfn[v]);
}
if(dfn[u] == low[u]) {
cnt++;
while() {
int now = stk[tot--];
scc[now] = cnt;
in[now] = false;
if(now == u) break;
}
}
} int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= m; i++) {
int u, v; scanf("%d%d", &u, &v);
if(u < && v < ) flag = true;
if(u < ) u = n - u;
if(v < ) v = n - v;
if(u <= n) G[u+n].push_back(v);
else G[u-n].push_back(v);
if(v <= n) G[v+n].push_back(u);
else G[v-n].push_back(u);
}
for(int i = ; i <= n<<; i++)
if(!dfn[i]) tarjan(i);
for(int i = ; i <= n; i++)
if(scc[i] == scc[i+n])
return puts(""), ;
if(!flag) return puts("-1"), ;
for(int i = ; i <= n; i++, cnt = , idx = ) {
G[i+n].push_back(i);
for(int j = ; j <= n<<; j++) dfn[j] = ;
for(int j = ; j <= n<<; j++) if(!dfn[j]) tarjan(j);
for(int j = ; j <= n; j++)
if(scc[j] == scc[j+n])
return puts(""), ;
G[i+n].pop_back();
}
puts("");
return ;
} /*
*/

2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) M - Unsatisfying 2-Sat的更多相关文章

  1. 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解

    题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...

  2. 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)

    2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) 思路: A Exam 思路:水题 代码: #include<bits ...

  3. Contest Setting 2018 ICPC Pacific Northwest Regional Contest dp

    题目:https://vj.69fa.cn/12703be72f729288b4cced17e2501850?v=1552995458 dp这个题目网上说是dp+离散化这个题目要对这些数字先处理然后进 ...

  4. 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution

    A:Alphabet Solved. 签. #include<bits/stdc++.h> using namespace std; ]; ]; int main(){ scanf(); ...

  5. 2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) S Surf

    SurfNow that you've come to Florida and taken up surng, you love it! Of course, you've realized that ...

  6. 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) 题解

    [题目链接] A - Alphabet 最长公共子序列.保留最长公共子序列,剩余的删除或者补足即可. #include <bits/stdc++.h> using namespace st ...

  7. 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution

    A:Exam Solved. 温暖的签. #include<bits/stdc++.h> using namespace std; ; int k; char str1[maxn], st ...

  8. 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) K Tournament Wins

    题目链接:http://codeforces.com/gym/101201 /* * @Author: lyucheng * @Date: 2017-10-22 14:38:52 * @Last Mo ...

  9. 2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)

    A. Odd Palindrome 所有回文子串长度都是奇数等价于不存在长度为$2$的偶回文子串,即相邻两个字符都不同. #include<cstdio> #include<cstr ...

随机推荐

  1. 51nod 1181 质数中的质数

    1181 质数中的质数(质数筛法) 题目来源: Sgu 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 如果一个质数,在质数列表中的编号也是质数,那么就称 ...

  2. 动态规划:树形DP-景点中心(树的带权重心)

    话说宁波市的中小学生在镇海中学参加计算机程序设计比赛,比赛之余,他们在镇海中学的各个景点参观.镇海中学共有n个景点,每个景点均有若干学生正在参 观.这n个景点以自然数1至n编号,每两个景点的编号均不同 ...

  3. 搭建SVN+APACHE环境

    项目需求 根据开发需求,建立svn环境,同时建立source.bd分支,source分支所有人都能访问,bd分支管理员kazihuo可访问.同时,在此基础上构建apache,以便于相关人员能通过浏览器 ...

  4. WebService环境变量

    将axis2部署到tomcat的webapps文件夹下: 因为该路径用于自动部署Web应用,将Web应用复制在该路径下,tomcat会将应用自动部署在容器中. AXIS_LIB:F:\tomcat\w ...

  5. 2016-2017-2 《Java程序设计》第七周学习总结

    20155313 2016-2017-2 <Java程序设计>第七周学习总结 第十二章 Lambda 12.1认识Lambda语法 12.1.1Lambda语法概览 在java中引入了La ...

  6. linux配置网路 设定主机名 ssh bash命令 通配符

    临时配置网络(ip,网关,dns) #ifconfig ens33 192.168.185/24 #ens33网卡名称.192.168.185/24是要配置的ip地址/子网掩码 #vim /etc/r ...

  7. 关于在函数中使用Array.prototype.slice.call而不是直接用slice

    arguments是每个函数在运行的时候自动获得的一个近似数组的对象(除了length外没有其他属性),这个arguments对象其实并不是Array,所以没有slice方法. Array.proto ...

  8. Runtime - Associated Objects (关联对象) 的实现原理

    主要围绕3个方面说明runtime-Associated Objects (关联对象) 1. 使用场景 2.如何使用 3.底层实现 3.1  实现原理 3.2 关联对象被存储在什么地方,是不是存放在被 ...

  9. unity 优秀开源项目

    ihaiu.GUIDRef (查看项目资源使用情况) http://blog.ihaiu.com/unity-GUIDRef Ihaiu.PoolManager (对象池) http://github ...

  10. poj3636

    题意:每个物品有两个属性:长和宽(长宽不可互换).如果一个物品的长和宽均大于另一个物品,则这个物品可以罩住另一个物品,用这种罩住物品的方法将物品分组,一组之内的物品可以一个罩住一个的全部罩起来.问最少 ...