在这题上不是标准的“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)的更多相关文章

  1. Codeforces 875C National Property(拓扑排序)

    题目链接  National Property 给定n个单词,字符集为m 现在我们可以把其中某些字母变成大写的.大写字母字典序大于小写字母. 问是否存在一种方案使得给定的n个单词字典序不下降. 首先判 ...

  2. CodeForces - 876E National Property(2-sat)

    题意:有n个有小写字母组成的字符串,将部分小写字母改成对应的大写字母,注意某种小写字母更改,所有的这种小写字母都会更改.若能使这给定的n个字符串符合字典序由小到大排序,则输出Yes,并输出需要修改的字 ...

  3. Codeforces 828B Black Square(简单题)

    Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...

  4. 1114 Family Property (25 分)

    1114 Family Property (25 分) This time, you are supposed to help us collect the data for family-owned ...

  5. Codeforces C. Maximum Value(枚举二分)

    题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. 【刷题-PAT】A1114 Family Property (25 分)

    1114 Family Property (25 分) This time, you are supposed to help us collect the data for family-owned ...

  7. 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 ...

  8. CodeForces 215B Olympic Medal(数学啊)

    题目链接:http://codeforces.com/problemset/problem/215/B Description The World Programming Olympics Medal ...

  9. CodeForces 993B Open Communication(STL 模拟)

    https://codeforces.com/problemset/problem/993/b 这题不难,暴力就能过,主要是题意太难懂了 题意: 现在有两个人,每个人手中有一对数,第一个人手中的数是n ...

随机推荐

  1. vue watch 的简单使用

    在项目开发中遇到的需求,这点写第一个dome 监听父组件传过来的值发送变化 在子组件中 <template> <div class="components"> ...

  2. Microsoft Compiled HTML Help / Uncompiled .chm File XML External Entity

    [+] Credits: John Page (aka hyp3rlinx) [+] Website: hyp3rlinx.altervista.org[+] Source:  http://hyp3 ...

  3. Qt 子线程更新Ui

    最近做练习,写一个Qt版的飞机大战,需要用子线程更新UI,发现Qt子线程不能更新Ui,否则程序会崩溃.在网上百度了下,说是需要在子线程自定义信号,然后在线程回调的run()函数里发射信号,主线程连接信 ...

  4. sqlite移植

    编译 # tar xvf sqlite-3.6.16.tar.gz # cd sqlite-3.6.16 # ./configure # ./configure --host=arm-linux -- ...

  5. 如何打包ANE

    来源:http://blog.sina.com.cn/s/blog_6471e1bb01012aql.html 首先先说一下打包ANE必须的部件: 1.ActionScript扩展库SWC 2.本机扩 ...

  6. robot framework笔记(二):在RF中自定义chrome启动参数

    (一)在RF中自定义chrome启动参数 这里主要是实现下面2个功能 1.禁用chrome正受自动测试软件控制的提示 2.设置默认的下载路径(一些导出.下载类的功能,将文件下载到指定路径下) 自定义一 ...

  7. 【JUC】5.线程池—Executor

    创建线程池可以分为三种方式: 1. 通过ThreadPoolExecutor的构造方法,创建ThreadPoolExecutor的对象,即一个线程池对象: 此构造方法,一共7个参数,5个必须参数,2个 ...

  8. Kubernetes 1.15部署日记-使用kubeadm--<1-2-3-4>

    2019年9月17日 由于此次日记篇幅较长blog限制直接使用word发布所以分成几篇来发. 1.环境准备 10.110.149.172|192.168.111.51 K8s-1 Centos7.5 ...

  9. c# Path类

  10. Mongodb3.6 Replica Set 配置

    单机下执行: /usr/local/mongodb/bin/mongod --dbpath /usr/local/mongodb/r1 --port --replSet myset /usr/loca ...