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 ...
随机推荐
- soapui调用redis,获取短信验证码
1.首先,调用redis需要引入redis的jar包,放入到soapui指定目录中,例如我的目录D:\Program Files\SmartBear\SoapUI-Pro-5.1.2\bin\ext ...
- JDK8新增接口的默认方法与静态方法
JDK8之前,interface中可以定义常量和抽象方法,访问修饰符是public. public interface A { /** a1和a2写法是等价的 */ public static fin ...
- docker容器的操作
容器操作 1.查看本地容器 docker ps -a # 查看所有容器 docker ps # 查看所有正在运行的容器 2.容器的创建与启动 方法一:两步完成(强烈推荐方法)(1)创建 docker ...
- js 判断浏览器型号
<html><head> <meta http-equiv="Content-Type" content="text/html;charse ...
- VS2015 新建 ASP.NET Web应用程序, 此模板尝试加载程序集‘Microsoft.VisualStudio.Web.Project’, 解决方案
下载并安装Azure的SDK即可:
- Oracle 10g收集数据库统计信息
1.需求概述 2.实施步骤 3.回退方案 1.需求概述 某数据库由于整体统计信息不准确,多次出现部分业务SQL选错执行计划,从而导致性能下降影响到最终用户体验,目前通过SQL_PROFILE绑定执行计 ...
- C# 获取 mp3文件信息【包括:文件大小、歌曲长度、歌手、专辑】
C# 获取 mp3文件信息[包括:文件大小.歌曲长度.歌手.专辑] 第一种方式:[代码已验证] // http://bbs.csdn.net/topics/390392612 string fil ...
- 关于easy ui 的combobox遍历选中
$.post("fleetAction!queryAllCompanyByCompanyID.do",{"truckCompany.id":companyId} ...
- python扩展包的升级
检查更新:pip list --outdated 更新: pip install --upgrade xxxx
- 查看 chrome 浏览器中的 Headers
查看 chrome 浏览器中的 Headers, Response 信息: