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 ...
随机推荐
- Docker入门3------手动编辑自定义镜像
手动编辑自定义镜像 查看本地现有镜像: 基于centos创建一个,会自动下载centos最新原始镜像 docker run -it --name=web centos /bin/bash 然后在容器内 ...
- Jmeter学习之-获取登录的oken值(2)
此篇介绍获取登录token的第二种方式--json提取器提取 PS:此方法针对接口返回值为json串格式 在登录请求上右键添加JSON提取器 ...
- mysql 目录
初识数据库 mysql 初识sql语句 mysql 操作sql语句 mysql 数据库操作 mysql 数据表操作 mysql 数据操作 mysql 权限管理 mysql内置功能之视图.触发器.事务. ...
- 使用Sqlserver事务发布实现数据同步(zhuanqian)
事务的功能在sqlserver中由来已久,因为最近在做一个数据同步方案,所以有机会再次研究一下它以及快照等,发现还是有很多不错的功能和改进的.这里以sqlserver2008的事务发布功能为例,对发布 ...
- nginx----------linux下nginx环境搭建遇到的一些问题汇总(多域名配置,配置文件修改问题)
一.启动 cd usr/local/nginx/sbin ./nginx 二.重启 更改配置重启nginx kill -HUP 主进程号或进程号文件路径 或者使用 cd /usr/local/ngin ...
- javascript Template tmpl
前两天写前端遇到很多table 和 表单需要拼接的问题 , 一堆的字符串 , 页面显得冗长,又不好维护.于是有了下文. 话不多说,上代码: 首先引用一个js文件: <script src=&qu ...
- 清华集训2017 Day 2简要题解
*注意:这套题目题面请在loj / uoj查看 从这里开始 题目列表(loj) Problem A 小 Y 和地铁 Problem B 小 Y 和二叉树 Problem C 小 Y 和恐怖的奴隶主 训 ...
- tp剩余未验证内容-7
bash脚本中 的 set -e表示 exit immediately if a simple command returns a non-zero value.主要是为了防止错误被忽略.会被立即退出 ...
- 微信小程序实现部分双向数据绑定(为input、picker、textarea编写统一的更新数据逻辑)
wepy开发小程序 以input为例,微信小程序没有数据双向绑定,input要显示绑定的数据即value等于一个绑定的量 <input type="text" value=& ...
- Linux常用命令——文件搜索命令
Linux常用命令——文件搜索命令 Linux 以#号开头的内容都是内容描述或配置项 find 描述:文件搜索 语法:find [搜索范围] [范围条件] . 当前目录 示例:[root@local ...