题目传送门

先把 = 的人用并查集合并在一起。

然后 < > 的建边, 跑一遍 toposort 之后就好了。

入度为0点的值肯定为1, 然后就是因为这个是按照时间线走过来的,所以一个点的最小值,就是在入队的那一刻确定的, 即入度为0的时候,值就是现在的值+1。

注意就是不要同一个点入队多次。

代码:

/*
code by: zstu wxk
time: 2019/02/24
*/
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 2e3 + ;
int pre[N];
int ind[N];
int val[N];
int n, m;
char s[N][N];
vector<int> vc[N];
int Find(int x){
if(x == pre[x]) return x;
return pre[x] = Find(pre[x]);
}
queue<int> q;
void toposort(){
for(int i = ; i <= n+m; ++i){
// cout << i << ' ' << ind[i] << endl;
if(i == Find(i) && ind[i] == ) {
q.push(i), val[i] = ;
// cout << i << endl;
}
}
while(!q.empty()){
int x = q.front();
q.pop();
for(int v : vc[x]){
ind[v]--;
if(ind[v] == ){
val[v] = val[x] + ;
q.push(v); }
}
}
}
void Ac(){
for(int i = ; i <= n + m; ++i) pre[i] = i, ind[i] = ;
for(int i = ; i <= n; ++i){
scanf("%s", s[i]+);
for(int j = ; j <= m; ++j){
if(s[i][j] == '='){
int u = Find(i), v = Find(n+j);
if(u == v) continue;
pre[u] = v;
}
}
}
for(int i = ; i <= n; ++i){
for(int j = ; j <= m; ++j){
if(s[i][j] == '=' ) continue;
int u = Find(i), v = Find(n+j);
if(s[i][j] == '<'){
vc[u].pb(v);
ind[v]++;
}
else {
vc[v].pb(u);
ind[u]++;
}
}
}
toposort();
for(int i = ; i <= n+m; ++i){
if(!val[Find(i)]){
puts("No");
return ;
}
}
puts("Yes");
for(int i = ; i <= n; ++i){
printf("%d%c", val[Find(i)]," \n"[i==n]);
}
for(int i = ; i <= m; ++i){
printf("%d%c", val[Find(i+n)], " \n"[i==m]);
}
}
int main(){
while(~scanf("%d%d", &n, &m)){
Ac();
}
return ;
}

CF - 1131 D Gourmet choice的更多相关文章

  1. CF#541 D. Gourmet choice /// BFS 拓扑

    题目大意: 给定n m 第一行有n个数 第二行有m个数 接下来n行每行m列 有 = < > 位于 i j 的符号表示 第一行第i个数与第二行第j个数的大小关系 1.将n+m个数 当做按顺序 ...

  2. coderfoces D. Gourmet choice

      D. Gourmet choice time limit per test 2 seconds memory limit per test 256 megabytes   题目链接: https: ...

  3. D. Gourmet choice并查集,拓扑结构

    D. Gourmet choice time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. 【CF #541 D】 Gourmet choice

    link:https://codeforces.com/contest/1131 题意: 给定一些大小比较,输出排名. 思路: 这道题我用的是拓扑排序,又因为有等于号的存在,我用了并查集. 结束后这道 ...

  6. codeforces #541 D. Gourmet choice(拓扑+并查集)

    Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the wo ...

  7. CF1131D Gourmet choice(并查集,拓扑排序)

    这题CF给的难度是2000,但我感觉没这么高啊…… 题目链接:CF原网 题目大意:有两个正整数序列 $a,b$,长度分别为 $n,m$.给出所有 $a_i$ 和 $b_j(1\le i\le n,1\ ...

  8. CF1131D Gourmet choice

    题目链接 题意 有两组菜,第一组有\(n\)种,第二组有\(m\)种.给出一个\(n\times m\)的矩阵,第\(i\)行第\(j\)列表示第一组中的第\(i\)种菜与第二组中的第\(j\)种菜好 ...

  9. CF 1131 E. String Multiplication

    E. String Multiplication 题意 分析: 从后往前考虑字符串变成什么样子. 设$S_i = p_1 \cdot p_2 \dots p_{i}$,最后一定是$S_{n - 1} ...

随机推荐

  1. MySQL 之 Explain 输出分析

    ​MySQL 之 Explain 输出分析 背景 前面的文章写过 MySQL 的事务和锁,这篇文章我们来聊聊 MySQL 的 Explain,估计大家在工作或者面试中多多少少都会接触过这个.可能工作中 ...

  2. redis过期策略与内存淘汰机制分析

    过期策略: 我们在set key时,可以给一个expire time,就是过期时间 这段过期时间以后,redis对key删除使用:定期删除+惰性删除 定期删除指redis默认在100ms内随机抽取一些 ...

  3. 安装MySQL5.7 安装环境:CentOS7 64位 MINI版,

    安装环境:CentOS7 64位 MINI版,安装MySQL5.7 1.配置YUM源 在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo ...

  4. 逆向破解之160个CrackMe —— 001

    CrackMe —— 001 160 CrackMe 是比较适合新手学习逆向破解的CrackMe的一个集合一共160个待逆向破解的程序 CrackMe:它们都是一些公开给别人尝试破解的小程序,制作 c ...

  5. Educational Codeforces Round 70 (Rated for Div. 2)

    这次真的好难...... 我这个绿名蒟蒻真的要崩溃了555... 我第二题就不会写...... 暴力搜索MLE得飞起. 好像用到最短路?然而我并没有学过,看来这个知识点又要学. 后面的题目赛中都没看, ...

  6. Spring 5 新功能:函数式 Web 框架

    英文:ARJEN POUTSMA 译文:debugging, 达尔文, 混元归一, leoxu, xufuji456 链接:oschina.net/translate/new-in-spring-5- ...

  7. 深入理解 linux磁盘顺序写、随机写

    一.前言 ● 随机写会导致磁头不停地换道,造成效率的极大降低:顺序写磁头几乎不用换道,或者换道的时间很短 ● 本文来讨论一下两者具体的差别以及相应的内核调用 二.环境准备 组件 版本 OS Ubunt ...

  8. Codeforces 868E Policeman and a Tree

    题意简述 给你一颗有n个点的树,每条边有边权,有一个警察一开始在点S,他的速度是1,即通过一条长度为x的边要花x单位时间. 有m个罪犯,一开始第i个在点x[i],他们的速度无限快. 如果罪犯和警察到达 ...

  9. mybatis批量更新策略

    我们知道循环中操作db会导致连接数满,严重影响数据库性能.所以在对db进行DQL与DML时,根据业务逻辑尽量批量操作,这里我们介绍下使用mybatis批量更新mysql的两种方式. 方式一: < ...

  10. java学习二

    一.类 1.类是模子,确定对象将会拥有的特征(属性)和行为(方法) 2.类的特点: (1).类是对象的类型 (2).具有相同属性和方法的一组对象的集合 3.类是抽象的概念,仅仅是模板,比如说:“手机” ...