题目传送门

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

然后 < > 的建边, 跑一遍 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. spring学习笔记之---bean属性注入

    bean属性注入 (一)构造方法的属性注入 1.Student.java package entity; public class Student { private String name; pri ...

  2. kube-scheduler源码分析

    kubernetes集群三步安装 kube-scheduler源码分析 关于源码编译 我嫌弃官方提供的编译脚本太麻烦,所以用了更简单粗暴的方式编译k8s代码,当然官方脚本在编译所有项目或者夸平台编译以 ...

  3. ThreadLocal线程隔离

    package com.cookie.test; import java.util.concurrent.atomic.AtomicInteger; /** * author : cxq * Date ...

  4. 初试kafka消息队列中间件二(采用java代码收发消息)

    初试kafka消息队列中间件二(采用java代码收发消息) 上一篇 初试kafka消息队列中间件一 今天的案例主要是将采用命令行收发信息改成使用java代码实现,根据上一篇的接着写: 先启动Zooke ...

  5. SQL Labs刷题补坑记录(less1-less30)

    补坑加1,这几天快速刷一下sqllabs 来巩固下sql注入基础吧,也算是把很久以前没刷的过一遍,do it! 第一部分: LESS1: 直接报错,有回显的注入, http://localhost/s ...

  6. 伪分布式Spark + Hive on Spark搭建

    Spark大数据平台有使用一段时间了,但大部分都是用于实验而搭建起来用的,搭建过Spark完全分布式,也搭建过用于测试的伪分布式.现在是写一遍随笔,记录一下曾经搭建过的环境,免得以后自己忘记了.也给和 ...

  7. SVN服务器更改ip地址客户端怎么设置

    SVN 服务器 IP 地址修改后,客户端对服务器的连接可以采用以下的方法重定位: 1. 如果客户端工具是TortoiseSVN,直接在工作副本上右键,选择TortoiseSVN->relocat ...

  8. C# 读取CAD文件缩略图(DWG文件)

    //C# 读取CAD文件缩略图(DWG文件) https://blog.csdn.net/hanghangaidoudou/article/details/8589574 //2010-09-04 1 ...

  9. c语言实现基本的数据结构(三) 栈

    #include <stdio.h> #include <tchar.h> #include <stdlib.h> #define StackSize 5 #def ...

  10. 访问CGI程序时不添加 /cgi-bin/ 目录也可访问

    配置如下 <VirtualHost *:80> DocumentRoot D:\web_root\test ServerName www.test.com <Directory /& ...