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 ...
随机推荐
- OO——UML解析
目录 第四单元博客作业 一.前两次作业架构设计 1. 第一次作业 2. 第二次作业 二.架构设计以及对OO方法理解的演进 1. 表达式求导 2. 多线程电梯 3. 地铁线路查询 4. UML图的解析 ...
- FreeRTOS队列操作
API函数 //创建 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) #define xQueueCreate( uxQueueLength, uxItemS ...
- HTTP协议复习一--认识HTTP
HTTP 是什么 HTTP 是一个在计算机世界里专门在两点之间传输文字.图片.音频.视频等超文本数据的约定和规范. HTTP 是一个用在计算机世界里的协议,它确立了一种计算机之间交流通信的规范,以及相 ...
- 服务接口,选择rpc还是http?
从通信内容/功能上看 http应用于web环境,rpc应用于分布式调度从功能上看没有太大区别,很多情况下rpc与消息中间件结合通信实现分布式调度 从用法上看两者都是c/s结构,无太大区别 从实现上看类 ...
- FastDFS+Nginx搭建Java分布式文件系统
一.FastDFS FastDFS是用c语言编写的一款开源的分布式文件系统.FastDFS为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标,使用FastDFS ...
- M - Ordering Tasks(拓扑排序)
M - Ordering Tasks Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descri ...
- ubuntu-网络配置文件
vim /etc/NetworkManager/system-connections/Wired connectione 1
- git学习记录--标签随笔
创建标签: 命令git tag <name>用于新建一个标签,默认为HEAD,也可以指定一个commit id: git tag -a <tagname> -m "b ...
- Java--8--新特性--Optional--有效防止空指针异常
Optional<T> 类(java.util.Optional) 是一个容器类,代表一个值存在或不存在,原来用 null 表示一个值不存在,现在 Optional 可以更好的表达这个概念 ...
- Linux 绑定 ttyUSBn 串口方法。
Linux 绑定 ttyUSBn 串口方法. 在linux下, 使用usb转串口, 经常会碰到一个问题: 如果有多个串口, 以不同顺序插入的时候, /dev/ttyUSB0 /dev/ttyUSB1的 ...