Codeforces 876E National Property ——(2-SAT)
在这题上不是标准的“a或b”这样的语句,因此需要进行一些转化来进行建边。同时在这题上点数较多,用lrj大白书上的做法会T,因此采用求强连通分量的方法来求解(对一个点,如果其拓扑序大于其为真的那个点,则这个语句为真,都相同则无解,否则为假)。AC代码如下:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + ;
typedef long long ll; int n,m,dfs_clock,dfn[N*],low[N*];
int belong[N*],scc_cnt;
stack<int> S;
vector<int> G[N*]; void init()
{
for(int i=;i<=n;i++) G[i].clear();
dfs_clock = ;
memset(dfn,,sizeof(dfn));
memset(belong,,sizeof(belong));
scc_cnt = ;
} void tarjan(int u)
{
dfn[u]=low[u]=++dfs_clock;
S.push(u);
for(int i=;i<G[u].size();i++)
{
int v = G[u][i];
if(!dfn[v])
{
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(!belong[v])
{
low[u]=min(low[u],dfn[v]);
}
}
if(low[u]==dfn[u])
{
scc_cnt++;
for(;;)
{
int x = S.top();S.pop();
belong[x] = scc_cnt;
if(x==u) break;
}
}
} void add(int x, int y) {G[x].push_back(y);} void solve()
{
for(int i=;i<*m;i++)
{
if(!dfn[i]) tarjan(i);
}
vector<int> ans; for(int i=;i<*m;i+=)
{
if(belong[i] == belong[i+])
{
puts("No");
return ;
}
else
{
if(belong[i] > belong[i+]) ans.push_back(i/+);
}
}
puts("Yes");
printf("%d\n",ans.size());
for(int i=;i<ans.size();i++) printf("%d%c",ans[i],i==ans.size()-?'\n':' ');
} vector<int> v[N]; int main()
{
cin >> n >> m;
for(int i=;i<=n;i++)
{
int t; scanf("%d",&t);
while(t--)
{
int x; scanf("%d",&x);
v[i].push_back(x);
}
}
init();
for(int i=;i<n;i++)
{
int sz = min(v[i].size(), v[i+].size());
int pos = -;
for(int j=;j<sz;j++)
{
if(v[i][j] != v[i+][j])
{
pos = j;
break;
}
}
if(pos == -)
{
if(v[i].size() <= v[i+].size()) continue;
else return *puts("No");
}
int x = v[i][pos]-;
int y = v[i+][pos]-;
if(x < y)
{
add(y<<|, x<<|);
add(x<<, y<<);
}
else
{
add(x<<, x<<|);
add(y<<|, y<<);
}
}
solve();
return ;
}
Codeforces 876E National Property ——(2-SAT)的更多相关文章
- Codeforces 875C National Property(拓扑排序)
题目链接 National Property 给定n个单词,字符集为m 现在我们可以把其中某些字母变成大写的.大写字母字典序大于小写字母. 问是否存在一种方案使得给定的n个单词字典序不下降. 首先判 ...
- CodeForces - 876E National Property(2-sat)
题意:有n个有小写字母组成的字符串,将部分小写字母改成对应的大写字母,注意某种小写字母更改,所有的这种小写字母都会更改.若能使这给定的n个字符串符合字典序由小到大排序,则输出Yes,并输出需要修改的字 ...
- Codeforces 828B Black Square(简单题)
Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...
- 1114 Family Property (25 分)
1114 Family Property (25 分) This time, you are supposed to help us collect the data for family-owned ...
- Codeforces C. Maximum Value(枚举二分)
题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【刷题-PAT】A1114 Family Property (25 分)
1114 Family Property (25 分) This time, you are supposed to help us collect the data for family-owned ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) E. National Property(2-sat)
E. National Property time limit per test 1 second memory limit per test 512 megabytes input standard ...
- CodeForces 215B Olympic Medal(数学啊)
题目链接:http://codeforces.com/problemset/problem/215/B Description The World Programming Olympics Medal ...
- CodeForces 993B Open Communication(STL 模拟)
https://codeforces.com/problemset/problem/993/b 这题不难,暴力就能过,主要是题意太难懂了 题意: 现在有两个人,每个人手中有一对数,第一个人手中的数是n ...
随机推荐
- c#自制抽奖小程序
#region 第一部分界面设计 ; Button button = new Button(); Image[] images = new Image[N]; PictureBox[] picture ...
- 【kubernetes】通过rancher2部署k8s
1. K8S相关介绍 十分钟带你理解Kubernetes核心概念 2. 部署rancher # 更新操作系统软件包 yum update -y # 删除历史容器及数据 docker rm -f $(d ...
- SYBASE扩充日志段空间
有时候日志段空间满了使用下列语句也无济于事,又不能直接重启库,就加空间应急,dump tran QAS with truncate_only dump tran QAS with no_log sp_ ...
- Jmeter学习笔记(九)——响应断言
Jmeter中又一个元件叫断言,用于检查测试中得到的响应数据等是否符合预期.断言又13种,目前在使用过程中使用到的是响应断言. 有时候请求成功了并不代表测试通过,还要看影响返回的内容是否符合预期的结果 ...
- c# zip写comment注释
//生成的压缩文件为test.zip using (FileStream fsOut = File.Create("test.zip")) { //ZipOutputStream类 ...
- SAP云平台里的三叉戟应用
大家第一次看到SAP MTA这个词组,会联想到什么? Jerry第一次看到的时候,联想到的是那一个个足坛著名的三叉戟攻击组合. 海皇波塞冬(Poseidon),奥林匹斯十二神中地位仅次于宙斯的大神,海 ...
- KVM虚拟化之嵌套虚拟化nested
本文测试物理机为centos6.5 物理机使用Intel-V虚拟化架构,安装qemu-kvm版本0.12 我们知道,在Intel处理器上,KVM使用Intel的vmx(virtul machine e ...
- linux系统编程之文件与io(二)
今天继续学习文件与io,话不多说,开始进入正题: 文件的read和write系统调用: 说明:函数中出现在size_t和ssize_t是针对系统定制的数据类型: 下面以一个实现文件简单拷贝的示 ...
- Angular CLI behind the scenes, part one
原文:https://commandlinefanatic.com/cgi-bin/showarticle.cgi?article=art074 --------------------------- ...
- Visual Studio 各版本对应关系
Known Name Version Latest KB / Revision Visual Studio 6 6 Service Pack 6; 6.0.3790.0; VB6.0-KB290887 ...