首页 > 其他分享 >P4782 【模板】2-SAT

P4782 【模板】2-SAT

时间:2024-05-11 14:52:37浏览次数:14  
标签:va vb cout int ll P4782 include 模板 SAT

简记:
1.参考学习:
https://blog.csdn.net/qaqwqaqwq/article/details/126124806
https://www.cnblogs.com/cjjsb/p/9771868.html
2.代码:

#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<cmath>
#include<limits.h>
#include<climits>
#include<fstream>
#include<set>
#include<stack>
typedef long long ll;
using namespace std;
const int N = 2e6 + 20;
ll dfn, low[N], num[N];
ll  cnt,sccno[N];
stack<int>stk;
vector<int>G[N<<1];
void dfs(int u)
{
	low[u] = num[u] = ++dfn;
	stk.push(u);
	for (int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if (!num[v])
		{
			dfs(v);
			low[u] = min(low[u], low[v]);

		}
		else if (!sccno[v])low[u] = min(low[u], num[v]);
	}
	if (low[u] == num[u])
	{
		cnt++;
		while (1)
		{
			int v = stk.top();
			stk.pop();
			sccno[v] = cnt;
			if (u == v)break;
		}
	}
}
void tarjan(int n)
{
	dfn = cnt =0;
	memset(low, 0, sizeof(low));
	memset(num, 0, sizeof(num));
	for (int i = 1; i <= 2 * n; i++)
		if (!num[i])
			dfs(i);
}
bool tSAT(int n)
{
	tarjan(n);
	for (int i = 1; i <= n; i++)
		if (sccno[i] == sccno[i + n])
			return false;
	return true;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n, m; cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int a, b, va, vb; 
		cin >> a >> va >> b >> vb;
		int nota = !va, notb = !vb;
		G[a + nota * n].push_back(b + vb * n);
		G[b + notb * n].push_back(a + va * n);
	}
	if (tSAT(n))
	{
		cout << "POSSIBLE" << '\n';
		for (int i = 1; i <= n; i++)
		{
			int ax = sccno[i] > sccno[i + n];
			cout << ax << ' ';
		}
	}
	else cout << "IMPOSSIBLE";
	return 0;
}

记录下手滑的乐子时刻()

标签:va,vb,cout,int,ll,P4782,include,模板,SAT
From: https://www.cnblogs.com/zzzsacmblog/p/18186493

相关文章

  • bug模板
    项目场景:我的本地项目运行起来了,好接下来就是把我之前写的代码粘贴到home文件中,运行一下,报了170多个错问题描述报错如下图,eslint检测出来的报错如下图,eslint检测出来的原因分析:应该关闭eslint配置就行了,找了很多解决方案:找到你的vue.config.js,然后增加一行lintOnSave......
  • E. Lomsat gelral
    https://codeforces.com/contest/600/problem/E题意:给一颗树,如果当前叶子为根的树中数字出现最多次数为k,求该树中所有出现次数为k的数字之和。思路:dfs+线段树合并。总结:第一次接触线段树合并,整理了3个上午才整理出模板来,不知道这种线段树合并有没有区间更新的功能,这个题目是......
  • 模板集合
    hello~这里是nihachu(叫niki就好)!这里是各种算法的模板集合,主要是方便自己背板子用的,后续会不定期更新,希望能帮到和我一样的小伙伴,也希望各路大神可以帮忙指正或补充,thanks~(部分代码来自网络,若有侵权,请联系我删除,感谢!)二叉树相关:深度优先:前序遍历(根,左子树,右子树)voiddfs(i......
  • ACM算法竞赛代码模板(长期更新)
    C++算法模板基础算法排序快速排序voidquickSort(intq[],intl,intr){if(l>=r)return;inti=l-1,j=r+1,x=q[l+r>>1];while(i<j){doi++;while(q[i]<x);doj--;while(q[j]>x);......
  • 2021看雪SDC议题回顾 | SaTC:一种全新的物联网设备漏洞自动化挖掘方法
    https://zhuanlan.zhihu.com/p/431335767随着物联网技术的日新月异,未来物联网的应用将越来越广泛,但它同样也会带来大量安全漏洞。而当下IoT漏洞挖掘技术尚未完全成熟,许多人的信息安全意识不够强,技术革新面临着巨大的安全隐患。来自上海交通大学的陈力波老师所提出的SaTC:一种全新......
  • 《Decoupled Optimisation for Long-Tailed Visual Recognition》阅读笔记
    论文标题《DecoupledOptimisationforLong-TailedVisualRecognition》长尾视觉识别的解耦优化作者CongCong、ShiyuXuan、SidongLiu、ShiliangZhang、MauricePagnucco和YangSong、来自新南威尔士大学计算机科学与工程学院、北京大学计算机学院多媒体信息处理国家......
  • vue学习--模板语法(五、选项卡案例)
    案例:<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><scriptsrc="https://cdn.j......
  • vue学习--模板语法(四、属性样式绑定&流程语句)
    目录3.5属性绑定1.Vue如何动态处理属性?2.v-model的底层实现原理分析3.6样式处理1.class样式处理2.style样式处理3.7分支循环结构1.分支结构2.v-if与v-show区别3.循环结构3.5属性绑定1.Vue如何动态处理属性?v-bind指令用法<av-bind:href='url'>跳转</a>缩写形式<a......
  • setsate更新之后和usestate的区别
    1setsatesetState(updater[,callback])updater:object/function-用于更新数据callback:function-用于获取更新后最新的state值a构造函数是唯一建议给this.state赋值的地方b不建议直接修改state的值,因为这样不会重新渲染组件c自动进行浅合并(只会合并第1层)d......
  • Tarjan模板
    Tarjan模板#include<iostream>#include<vector>#include<algorithm>#include<math.h>#include<sstream>#include<string>#include<string.h>#include<iomanip>#include<stdlib.h>#include<map>#include......