2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) M - Unsatisfying 2-Sat
题目大意:给你 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的更多相关文章
- 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解
题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...
- 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)
2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) 思路: A Exam 思路:水题 代码: #include<bits ...
- Contest Setting 2018 ICPC Pacific Northwest Regional Contest dp
题目:https://vj.69fa.cn/12703be72f729288b4cced17e2501850?v=1552995458 dp这个题目网上说是dp+离散化这个题目要对这些数字先处理然后进 ...
- 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution
A:Alphabet Solved. 签. #include<bits/stdc++.h> using namespace std; ]; ]; int main(){ scanf(); ...
- 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 ...
- 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2) 题解
[题目链接] A - Alphabet 最长公共子序列.保留最长公共子序列,剩余的删除或者补足即可. #include <bits/stdc++.h> using namespace st ...
- 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 ...
- 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 ...
- 2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)
A. Odd Palindrome 所有回文子串长度都是奇数等价于不存在长度为$2$的偶回文子串,即相邻两个字符都不同. #include<cstdio> #include<cstr ...
随机推荐
- C语言复习---判断素数
一般 int main01() { ; scanf("%d", &a); n_sqrt = sqrt(a); ; i <= n_sqrt; i++) ) { flag ...
- Centos7远程桌面 vnc/vnc-server的设置
Centos7与Centos6.x有了很大的不同. 为了给一台服务器装上远程桌面,走了不少弯路.写这篇博文,纯粹为了记录,以后如果遇到相同问题,可以追溯. 1.假定你的系统没有安装vnc的任何软件,那 ...
- 深入剖析linq的联接
内联接 代码如下 from a in new List<string[]>{ ]{"张三","男"}, ]{"李四"," ...
- spring boot使用自定义配置的线程池执行Async异步任务
一.增加配置属性类 package com.chhliu.springboot.async.configuration; import org.springframework.boot.context ...
- 不忘初心,方得始终——NOIP2016前的感悟
不忘初心,方得始终 袛园精舍钟声响,奏诸世事本无常.沙罗双树失花色,盛者转衰如沧桑.骄者难久,恰如春宵一梦.猛者遂灭,好似风前之尘. ——题记 人生中最令人恐惧的恐怕就是选择了,现在的你拥有 ...
- 基本控件文档-UIKit结构图
CHENYILONG Blog 基本控件文档-UIKit结构图 Fullscreen UIKit结构图 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博htt ...
- serialize()传值缺失
思路:serialize()获取的是 " & " 拼接的字符串,无法传值,需要拆分后,拼接,生成新字符串,传过去. 例子: var v_idd = $("form ...
- 基于Vue + Vuex + Vue-router + Webpack 2.0打造微信界面
一.项目简介 基于Vue + Vuex + Vue-router + Webpack 2.0打造微信界面,实现了微信聊天.搜索.点赞.通讯录(快速导航).个人中心.模拟对话.朋友圈.设置等功能. 二. ...
- aarch64_o2
opensips-event_rabbitmq-2.2.3-1.fc26.aarch64.rpm 2017-03-10 01:22 42K fedora Mirroring Project opens ...
- C#抓取网络图片保存到本地
C#抓取网络图片保存到本地 System.Net.WebClient myWebClient = new System.Net.WebClient(); //将头像保存到服务器 string virP ...