National Property CodeForces - 875C (拓扑排序)
大意: n个字符串, 每次操作选出一种字符全修改为大写, 求判断能否使n个字符串字典序非降.
建源点s, 汇点t, s与所有必须转大写的连边, 必须不转大写的与t连边.
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <string.h>
#include <queue>
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define hr putchar('\n')
#define pb push_back
#define mp make_pair
#define mid (l+r>>1)
#define lc (o<<1)
#define rc (lc|1)
#define FI first
#define SE second using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head const int N = 4e5+10;
int a[N], b[N], c[N], vis[N], f[N], n, m, k, t;
vector<int> s[N], g[N]; void dfs(int x) {
if (vis[x]) return;
vis[x] = 1;
for (int y:g[x]) dfs(y);
} int main() {
scanf("%d%d", &n, &m);
REP(i,1,n) {
scanf("%d", &t);
while (t--) scanf("%d",&k),s[i].pb(k);
}
REP(i,1,n-1) {
int pos = 0;
for (; pos<s[i].size()&&pos<s[i+1].size()&&s[i][pos]==s[i+1][pos]; ++pos);
if (pos==s[i].size()) continue;
if (pos==s[i+1].size()) return puts("No"),0;
if (s[i][pos]>s[i+1][pos]) {
g[0].pb(s[i][pos]), g[s[i+1][pos]].pb(m+1);
} else {
g[s[i+1][pos]].pb(s[i][pos]);
}
}
dfs(0);
if (vis[m+1]) return puts("No"),0;
puts("Yes");
int ans = 0;
REP(i,1,m) ans+=vis[i];
printf("%d\n", ans);
REP(i,1,m) if (vis[i]) printf("%d ", i);hr;
}
National Property CodeForces - 875C (拓扑排序)的更多相关文章
- CF思维联系--CodeForces -214C (拓扑排序+思维+贪心)
ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that gre ...
- CodeForces - 721C 拓扑排序+dp
题意: n个点m条边的图,起点为1,终点为n,每一条单向边输入格式为: a,b,c //从a点到b点耗时为c 题目问你最多从起点1到终点n能经过多少个不同的点,且总耗时小于等于t 题解: 这道 ...
- Codeforces 1100E 拓扑排序
题意及思路:https://blog.csdn.net/mitsuha_/article/details/86482347 如果一条边(u, v),v的拓扑序小于u, 那么(u, v)会形成环,要反向 ...
- Codeforces 1159E 拓扑排序
题意及思路:https://www.cnblogs.com/dd-bond/p/10859864.html 代码: #include <bits/stdc++.h> #define LL ...
- Codeforces 875C National Property(拓扑排序)
题目链接 National Property 给定n个单词,字符集为m 现在我们可以把其中某些字母变成大写的.大写字母字典序大于小写字母. 问是否存在一种方案使得给定的n个单词字典序不下降. 首先判 ...
- Codeforces Gym-102219 2019 ICPC Malaysia National J. Kitchen Plates (暴力,拓扑排序)
题意:给你5个\(A,B,C,D,E\)大小关系式,升序输出它们,如果所给的大小矛盾,输出\(impossible\). 题意:当时第一眼想到的就是连边然后排序,很明显是拓扑排序(然而我不会qwq,之 ...
- Codeforces Round #292 (Div. 1) B. Drazil and Tiles 拓扑排序
B. Drazil and Tiles 题目连接: http://codeforces.com/contest/516/problem/B Description Drazil created a f ...
- Codeforces Beta Round #29 (Div. 2, Codeforces format) C. Mail Stamps 离散化拓扑排序
C. Mail Stamps Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
随机推荐
- Linux 从源码编译安装 OpenSSH
https://blog.csdn.net/bytxl/article/details/46639073 Linux 从源码编译安装 OpenSSH以及各问题解决 2015年06月25日 17:37: ...
- 关于STM32时钟系统
初学STM32,感觉最蛋疼的是它的时钟系统,每次看到它的那个时钟树就有点晕,虽然看了很多这方面的资料,甚至也已经写过很多STM32的模块代码,做过一些小项目,但一直还是对这一块模模糊糊,似懂非懂,所以 ...
- LeetCode 448 Find All Numbers Disappeared in an Array 解题报告
题目要求 Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice a ...
- docker小结
docker命令汇总 https://www.cnblogs.com/andy9468/p/10762742.html docker概述 https://www.cnblogs.com/andy946 ...
- Python Async/Await入门指南
转自:https://zhuanlan.zhihu.com/p/27258289 本文将会讲述Python 3.5之后出现的async/await的使用方法,以及它们的一些使用目的,如果错误,欢迎指正 ...
- kendo treeview checkbox初始化选中问题,没解决,暂时记录下
想做带有checkbox的tree,由于项目一直用kendo ui for mvc,感觉 牛逼的kendo肯定有tree.结果碰到了选中的问题. 无法根据后台传来的IsChecked字段来设置 tr ...
- androidstudio项目如何使用git版本回退
使用android studio 编写代码错误,有时可能会需要将项目版本回退到以前的某个版本上,这对于很多刚使用git的网友来说操作可能不是很懂,下面为大家整理了android studio 回退已经 ...
- ubuntu apache 配置虚拟主机 与 二级域名
一.ubuntu 配置虚拟主机 方法一:添加端口号 第一步进入 /etc/apache2/sites-available/ 目录,将 000-default.conf 复制一份到当前目录下并重命名,然 ...
- 详解Python变量在内存中的存储
这篇文章主要是对python中的数据进行认识,对于很多初学者来讲,其实数据的认识是最重要的,也是最容易出错的.本文结合数据与内存形态讲解python中的数据,内容包括: 引用与对象 可变数据类型与不可 ...
- Kubernetes资源管理
目录贴:Kubernetes学习系列 1.资源模型 虛拟化技术是云计算平台的基础,其目标是对计算资源进行整合或划分,这是云计算管理平台中的关键技术.虚拟化技术为云计算管理乎台的资源管理提供了资源调配上 ...