在这题上不是标准的“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. rabbitMq 学习笔记(二) 备份交换器,过期时间,死信队列,死信队列

    备份交换器 备份交换器,英文名称为 Altemate Exchange,简称庙,或者更直白地称之为"备胎交换器". 生产者在发送消息的时候如果不设置 mandatory 参数, 那 ...

  2. 【转载】C#中List集合使用Remove方法移除指定的对象

    在C#的List集合操作中,有时候需要将特定的对象或者元素移除出List集合序列中,此时可使用到List集合的Remove方法,Remove方法的方法签名为bool Remove(T item),it ...

  3. H5打开app指定页面(H5+app项目)

    H5+app项目,在HBuilderX中设置 详情参考官方 https://ask.dcloud.net.cn/article/64 给h5+app设置scheme值,作用:在其它app和h5页面中启 ...

  4. linux之expect用法

    1. [#!/usr/bin/expect] 这一行告诉操作系统脚本里的代码使用那一个shell来执行.这里的expect其实和linux下的bash.windows下的cmd是一类东西. 注意:这一 ...

  5. typescript_类

    //类的定义 class Animal{ id:string;//默认访问修饰符为 public : 类本身.子类.类外部可访问 public name:string; // public : 类本身 ...

  6. Deep learning_CNN_Review:A Survey of the Recent Architectures of Deep Convolutional Neural Networks——2019

    CNN综述文章 的翻译 [2019 CVPR] A Survey of the Recent Architectures of Deep Convolutional Neural Networks 翻 ...

  7. Android自动化测试探索(一)adb详细介绍

    adb详细介绍 #1. 基本简介 adb,即Android Debug Bridge,它是Android开发/测试人员不可替代的强大工具 #2. Mac上安装adb 安装brew /usr/bin/r ...

  8. 编写订单支付api中遇到的问题

    首先我是按照已经有的已经有的支付api去编写订单支付api,但是由于两者是有区别的,所以类似去搬用难免会出问题,首先我是套用已经写好的model,然后写相应的serializer,实现序列化之后就开始 ...

  9. 汽车电子测试项目管理系统-TPA

    概述 INTEWORK-TPA(Test Project Administrator, 以下简称TPA) 是一款集成的测试项目管理工具,它可以管理测试过程中的所有数据,包括需求.用例.样件.计划.报告 ...

  10. linux的virtualenv和virtualenvwarpper

    转自:https://www.cnblogs.com/qq631243523/p/10191748.html 一,介绍 在使用 Python 开发的过程中,工程一多,难免会碰到不同的工程依赖不同版本的 ...