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 ...
随机推荐
- Celery定时任务细讲
Celery定时任务细讲 一.目录结构 任务所在目录 ├── celery_task # celery包 如果celery_task只是建了普通文件夹__init__可以没有,如果是包一定要有 │ ├ ...
- 解决SecureCRT 中文乱码??
在linux服务器上搭建solr,用的是SecureCRT 连接linux服务器,发现不能输入中文,配置文件中的中文也是乱码:先以为是SecureCRT工具编码的问题,把编码改成utf-8之后发现还 ...
- 【阿里云开发】- 安装JDK
1.阿里云轻量服务器入口 https://swas.console.aliyun.com/?spm=5176.2020520001.1011.2.29ff4bd3P4AEDc#/servers 2.使 ...
- vue使用vuex大体结构
store1.js const state = {} const mutations = {} const actions = {} const getters = {} export default ...
- a标签中target属性为“_blank”时存在安全问题
今天看到一个比较有意思的洞,虽然不够严重,但是却普遍存在各大src中 熟悉js的朋友都应该知道当我们在调用window下的open方法创建一个新窗口的同时,我们可以获得一个创建窗口的opener句柄, ...
- SIM7500 SIM7600 SIM800 HTTP
解释 //Start HTTP service AT+HTTPINIT //Stop HTTP service AT+HTTPTERM //Set HTTP Parameters value /* & ...
- Python学习日记(十九) 模块导入
模块导入 当文件夹中有这样一个自定义的command模块 在它的内部写下下列代码: print('这个py文件被调用!') def fuc(): print('这个函数被调用!') 然后我们在comm ...
- VSCode - Beautify插件配置
注: 本文摘自 黑火巨雷 - 简书 1. 在工作目录下建立.jsbeautifyrc文件 官方文档 { "brace_style": "none,preserve-inl ...
- Mybatis中传递多个参数的方法总结
一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...
- log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment)的解决
报错:log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironme ...