Gourmet choice

5 篇文章 0 订阅

传送门

题目:

Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review  — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the dishes are different, because Mr. Apple doesn't like to eat the same food. For each pair of dishes from different days he remembers exactly which was better, or that they were of the same quality. After this the gourmet evaluates each dish with a positive integer.

Once, during a revision of a restaurant of Celtic medieval cuisine named «Poisson», that serves chestnut soup with fir, warm soda bread, spicy lemon pie and other folk food, Mr. Apple was very pleasantly surprised the gourmet with its variety of menu, and hence ordered too much. Now he's confused about evaluating dishes.

The gourmet tasted a set of nn dishes on the first day and a set of mm dishes on the second day. He made a table aa of size n×mn×m, in which he described his impressions. If, according to the expert, dish ii from the first set was better than dish jj from the second set, then aijaij is equal to ">", in the opposite case aijaij is equal to "<". Dishes also may be equally good, in this case aijaij is "=".

Now Mr. Apple wants you to help him to evaluate every dish. Since Mr. Apple is very strict, he will evaluate the dishes so that the maximal number used is as small as possible. But Mr. Apple also is very fair, so he never evaluates the dishes so that it goes against his feelings. In other words, if aijaij is "<", then the number assigned to dish ii from the first set should be less than the number of dish jj from the second set, if aijaij is ">", then it should be greater, and finally if aijaij is "=", then the numbers should be the same.

Help Mr. Apple to evaluate each dish from both sets so that it is consistent with his feelings, or determine that this is impossible.

Input

The first line contains integers nn and mm (1≤n,m≤10001≤n,m≤1000) — the number of dishes in both days.

Each of the next nn lines contains a string of mm symbols. The jj-th symbol on ii-th line is aijaij. All strings consist only of "<", ">" and "=".

Output

The first line of output should contain "Yes", if it's possible to do a correct evaluation for all the dishes, or "No" otherwise.

If case an answer exist, on the second line print nn integers — evaluations of dishes from the first set, and on the third line print mmintegers — evaluations of dishes from the second set.

Examples

input

Copy

3 4
>>>>
>>>>
>>>>

output

Copy

Yes
2 2 2 
1 1 1 1 

input

Copy

3 3
>>>
<<<
>>>

output

Copy

Yes
3 1 3 
2 2 2 

input

Copy

3 2
==
=<
==

output

Copy

No

Note

In the first sample, all dishes of the first day are better than dishes of the second day. So, the highest score will be 22, for all dishes of the first day.

In the third sample, the table is contradictory — there is no possible evaluation of the dishes that satisfies it.

题意:给你一个二维字符矩形,a(i,j)代表第一天的第i个>=<第j天的,让你对每一道菜赋值,使所有菜的最大值最小,然后如果有输出就输出每一天的菜品的值,如果没有值就输出No;

思路:对于一道菜没有菜品的值大于它,它的值就是最小的,也就是1,然后通过他去更新比它大的菜品,所以对二维数组进行建图后,让小的值指向大的值就可以转换成一个拓扑排序,而对于俩个相等的值,他们的大小关系是公用的,就可以引入一个并查集维护同一公共组先;

ac代码:

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
const int maxn=1005;
vector<int> v[maxn*2];
int fa[maxn*2],ans[maxn*2];
bool judge[maxn&2];
char map1[maxn][maxn];
int find1(int a){
    if(a==fa[a])
        return a;
    return fa[a]=find1(fa[a]);
}
map<int,int> m1;
int m2[maxn*2];
int len[maxn*2];
queue<int> q;
int main( )
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int a=1;a<=n+m;a++)
        fa[a]=a,ans[a]=0,judge[a]=false;
    for(int a=1;a<=n;a++){
        scanf("%s",map1[a]+1);
        for(int b=1;b<=m;b++){
            if(map1[a][b]=='='){
                int i=find1(a);
                int j=find1(n+b);
                if(i!=j)
                    fa[i]=j;
            }
        }
    }
    int top=0;
    for(int a=1;a<=n+m;a++){
        int i=find1(a);
        if(m1[i]==0){
            m1[i]=++top;
            len[top]=0;
            m2[i]=top;
        }
    }

    for(int a=1;a<=n;a++){
        for(int b=1;b<=m;b++){
            if(map1[a][b]=='=')
               continue;
            if(fa[a]==fa[b+n]){
               printf("No\n");
               return 0;
            }
            if(map1[a][b]=='>'){
                v[m2[fa[b+n]]].push_back(m2[fa[a]]);
                len[m2[fa[a]]]++;
            }
            else{
                v[m2[fa[a]]].push_back(m2[fa[b+n]]);
                len[m2[fa[b+n]]]++;
            }
        }
    }
    for(int a=1;a<=top;a++)
        if(len[a]==0){
           q.push(a);
           ans[a]=1;
        }
    int nu=0;
    while(!q.empty()){
        int i=q.front();
        q.pop();
        nu++;
        for(int a=0;a<v[i].size();a++){
            int j=v[i][a];
            len[j]--;
            if(len[j]==0){
                ans[j]=max(ans[i]+1,ans[j]);
                q.push(j);
            }
        }
    }
    if(nu!=top){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    for(int a=1;a<=n;a++){
        if(a!=n)
            printf("%d ",ans[m2[fa[a]]]);
        else
            printf("%d\n",ans[m2[fa[a]]]);
    }
    for(int a=n+1;a<=n+m;a++){
        if(a!=m+n)
            printf("%d ",ans[m2[fa[a]]]);
        else
            printf("%d\n",ans[m2[fa[a]]]);
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值