-
Notifications
You must be signed in to change notification settings - Fork 0
/
1131.D. Gourmet choice.cpp
69 lines (58 loc) · 1.16 KB
/
1131.D. Gourmet choice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "stdc++.h"
const int N = 2003;
VI e[N], ind, f;
int fa[N], n, m;
int find(int x) {
return fa[x]==x ? x : fa[x]=find(fa[x]);
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
ind.resize(n+m+1);
f = VI(n+m+1, 1);
iota(fa+1, fa+n+m+1, 1);
vector<string> rel(n+1);
REP(i, 1, n) {
cin >> rel[i];
FOR(j, m)
if (rel[i][j] == '=') {
fa[find(i)] = find(j+1+n);
}
}
REP(i, 1, n)
FOR(j, m) {
int fi = find(i), fj = find(j+1+n);
if (rel[i][j] != '=') {
if (fi == fj) {
cout << "NO\n";
return 0;
}
if (rel[i][j] == '>') swap(fi, fj);
e[fi].PB(fj);
++ind[fj];
}
}
queue<int> q;
REP(i, 1, n+m)
if (fa[i]==i && !ind[i])
q.push(i);
while (!q.empty()) {
POP(x, q);
for (auto y : e[x]) {
f[y] = max(f[y], f[x]+1);
if (--ind[y] == 0)
q.push(y);
}
}
REP(i, 1, n+m) {
f[i] = f[find(i)];
if (ind[i]) {
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
REP(i, 1, n) cout << f[i] << ' '; cout << endl;
REP(i, n+1, n+m) cout << f[i] << ' '; cout << endl;
return 0;
}