#include<bits/stdc++.h>
using namespace std;
vector<int>g[2007];
int fa[2007],vis[2007],num[2007];
char s[2007][2007];
int find_(int x){
    if(fa[x]==x)
        return x;
    return fa[x]=find_(fa[x]);//合并
}
void dfs(int u){
    vis[u]=-1;//正数说明有环,0说明需要dfs,so将其置为负数
    ++num[u];//从链尾dfs每次给链尾+1
    for(auto&i:g[u]){
        num[i]=max(num[i],num[u]);//链尾以后的数字至少大于链尾(可能在别的链中数字较大),先让它们都和链尾相同以后再通过dfs++
        if(!--vis[i])
            dfs(i);
    }
}
void addedge(int u,int v){
    g[u].push_back(v);//建图
    vis[v]++;//打上标记
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n+m;i++)
        fa[i]=i;//初始化
    for(int i=1;i<=n;i++){
        scanf("%s",s[i]+1);
        for(int j=1;j<=m;j++)
            if(s[i][j]=='=')
                fa[find_(i)]=find_(n+j);//缩点
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            if(s[i][j]=='<')
                addedge(find_(i),find_(n+j));//大的放后面
            else if(s[i][j]=='>')
                addedge(find_(n+j),find_(i));//大的放后面
        }
    int flag=0;
    for(int i=1;i<=n+m;i++)
        if(find_(i)==i&&!vis[i])//找一个代表与它同值的所有点的点并且没有被拜访过即链尾
            dfs(i);//dfs
    for(int i=1;i<=n+m;i++)
        if(find_(i)==i&&vis[i]>0){//正值说明有环
            flag=1;
            printf("No");//显然有环是不能安排的
            break;
        }
    if(!flag){
        printf("Yes\n");
        for(int i=1;i<=n;i++)
            printf("%d ",num[find_(i)]);//找到代表它的点的num值
        printf("\n");
        for(int i=1;i<=m;i++)
            printf("%d ",num[find_(i+n)]);//找到代表它的点的num值
    }
    return 0;
}

Codeforces Round #541 (Div. 2)D(并查集(dsu),拓扑排序)的更多相关文章

  1. Codeforces Round #541 (Div. 2) D 并查集 + 拓扑排序

    https://codeforces.com/contest/1131/problem/D 题意 给你一个n*m二维偏序表,代表x[i]和y[j]的大小关系,根据表构造大小分别为n,m的x[],y[] ...

  2. Codeforces Round #376 (Div. 2) C. Socks---并查集+贪心

    题目链接:http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,每只都有一个颜色,现在他的妈妈要去出差m天,然后让他每天穿第 L 和第 R 只 ...

  3. Codeforces Round #286 (Div. 2) B 并查集

    B. Mr. Kitayuta's Colorful Graph time limit per test 1 second memory limit per test 256 megabytes in ...

  4. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  5. Codeforces Round #285 (Div. 2)C. Misha and Forest(拓扑排序)

    传送门 Description Let's define a forest as a non-directed acyclic graph (also without loops and parall ...

  6. Codeforces Round #541 (Div. 2)

    Codeforces Round #541 (Div. 2) http://codeforces.com/contest/1131 A #include<bits/stdc++.h> us ...

  7. Codeforces Round #541 (Div. 2) D(并查集+拓扑排序) F (并查集)

    D. Gourmet choice 链接:http://codeforces.com/contest/1131/problem/D 思路: =  的情况我们用并查集把他们扔到一个集合,然后根据 > ...

  8. Codeforces 1131 F. Asya And Kittens-双向链表(模拟或者STL list)+并查集(或者STL list的splice()函数)-对不起,我太菜了。。。 (Codeforces Round #541 (Div. 2))

    F. Asya And Kittens time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #541 (Div. 2)题解

    不知道该更些什么 随便写点东西吧 https://codeforces.com/contest/1131 ABC 太热了不写了 D 把相等的用并查集缩在一起 如果$ x<y$则从$ x$往$y$ ...

  10. Codeforces Round #541 (Div. 2) (A~F)

    目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...

随机推荐

  1. HDFS之三:hdfs参数配置详解

    1.hdfs-site.xml 参数配置 – dfs.name.dir – NameNode 元数据存放位置 – 默认值:使用core-site.xml中的hadoop.tmp.dir/dfs/nam ...

  2. Spring之3:BeanFactory、ApplicationContext、ApplicationContextAware区别

    在Spring中系统已经为用户提供了许多已经定义好的容器实现,而不需要开发人员事必躬亲.相比那些简单拓展BeanFactory的基本IoC容器,开发人员常用的ApplicationContext除了能 ...

  3. Regexp:教程

    ylbtech-Regexp:教程 1.返回顶部 1. 正则表达式 - 教程 正则表达式(Regular Expression)是一种文本模式,包括普通字符(例如,a 到 z 之间的字母)和特殊字符( ...

  4. Even uploading a JPG file can lead to Cross-Site Content Hijacking (client-side attack)!

    Introduction: This post is going to introduce a new technique that has not been covered previously i ...

  5. AJAX——XMLHttpRequest对象的使用

    AJAX是web2.0即动态网页的基础,而XMLHttpRequest对象又是AJAX的核心.XMLHttpRequest对象负责将用户信息以异步通信地发送到服务器端,并接收服务器响应信息和数据 一. ...

  6. 如何利用MATLAB并行计算缩短程序运行时间

    本来CPU就是双核,不过以前一直注重算法,没注意并行计算的问题.今天为了在8核的dell服务器上跑程序才专门看了一下.本身写的程序就很容易实现并行化,因为beamline之间并没有考虑相互作用.等于可 ...

  7. Repmat:Replicate and tile an array

    Repmat:Replicate and tile an array Syntax B = repmat(A,m,n) B = repmat(A,[m n]) B = repmat(A,[m n p. ...

  8. LAMP 3.4 mysql常用操作-2

    给用户授权 > grant all on discuz.* to 'user1'@'192.168.1.%' identified by 'wangshaojun'; 指定库,用户名user1 ...

  9. mysql工具Navicat批量执行SQL语句

    例如:我现在要同时执行这么多语句 update community set xqmc=replace(xqmc,' ',''); update community set xqbm=replace(x ...

  10. elmah数据库sql脚本

    /* 错误管理工具 SQL代码 */CREATE TABLE dbo.ELMAH_Error( ErrorId UNIQUEIDENTIFIER NOT NULL, Application NVARC ...