#include <bits/stdc++.h>
using namespace std;
//#define int long long
const int MAXN = 3e5 + 5;
define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define OPEN freopen(".in", "r", stdin); \
freopen(".out", "w", stdout);
#else
#define OPEN void(23);
#endif
struct DSU
{
vector <int> par;
DSU(int n)
{
par.resize(n);
iota(par.begin(), par.end(), 0ll);
}
inline int get(int a)
{
return par[a] = (par[a] == a ? a : get(par[a]));
}
bool same(int u, int v)
{
return get(u) == get(v);
}
bool unite(int u, int v)
{
if(same(u, v)) return false;
u = get(u), v = get(v);
par[v] = u;
return true;
}
};
vector <int> adj[MAXN];
vector <int> compos[MAXN];
DSU dsu(MAXN);
vector <pair <int, int>> que;
vector <int> dists(MAXN, -1);
vector <int> colors(MAXN, -1);
vector <int> ans(MAXN, -1);
int dfsDist(int node)
{
if(dists[node] != -1) return dists[node];
dists[node] = 1;
for(const int &child : adj[node])
{
dists[node] = max(dfsDist(child) +1, dists[node]);
}
return dists[node];
}
void dfsCol(int node, int col)
{
colors[node] = col;
sort(adj[node].begin(), adj[node].end(), [&](int a, int b)
{
return dists[a] >= dists[b];
});
for(const int &child : adj[node])
{
if(colors[child] == -1) dfsCol(child, col +1);
}
}
void solve()
{
int n, m, v; cin >> n >> m >> v;
for(int i = 1; i <= v; i++)
{
int u = 0, v = 0; char eq;
cin >> u >> eq >> v;
if(eq == '>') swap(u, v);
if(eq == '=') dsu.unite(u, v);
else que.emplace_back(u, v);
}
for(auto &[a, b] : que)
{
adj[dsu.get(a)].emplace_back(dsu.get(b));
}
for(int i = 1; i <= m; i++) dfsDist(i);
for(int i = 1; i <= m; i++)
{
if(dists[i] == n) dfsCol(i, 1);
}
for(int i = 1; i <= m; i++) compos[dsu.get(i)].emplace_back(i);
for(int i = 1; i <= m; i++) ans[i] = colors[i];
for(int i = 1; i <= m; i++)
{
if(dsu.get(i) != i) continue;
int col = colors[i];
for(int &j : compos[i]) ans[j] = col;
}
for(int i = 1; i <= m; i++)
{
if(ans[i] == -1) cout << '?';
else cout << 'K' << ans[i];
cout << "\n";
}
return;
}
int32_t main()
{
OPEN;
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1; //cin >> t;
while(t--)
{
solve();
}
}
Compilation message
kovanice.cpp:7:1: error: 'define' does not name a type
7 | define ONLINE_JUDGE
| ^~~~~~
kovanice.cpp:46:1: error: 'DSU' does not name a type
46 | DSU dsu(MAXN);
| ^~~
kovanice.cpp: In function 'void solve()':
kovanice.cpp:87:23: error: 'dsu' was not declared in this scope
87 | if(eq == '=') dsu.unite(u, v);
| ^~~
kovanice.cpp:93:13: error: 'dsu' was not declared in this scope
93 | adj[dsu.get(a)].emplace_back(dsu.get(b));
| ^~~
kovanice.cpp:103:40: error: 'dsu' was not declared in this scope
103 | for(int i = 1; i <= m; i++) compos[dsu.get(i)].emplace_back(i);
| ^~~
kovanice.cpp:109:12: error: 'dsu' was not declared in this scope
109 | if(dsu.get(i) != i) continue;
| ^~~
kovanice.cpp: In function 'int32_t main()':
kovanice.cpp:9:25: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | #define OPEN freopen(".in", "r", stdin); \
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
kovanice.cpp:126:5: note: in expansion of macro 'OPEN'
126 | OPEN;
| ^~~~
kovanice.cpp:10:25: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | freopen(".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
kovanice.cpp:126:5: note: in expansion of macro 'OPEN'
126 | OPEN;
| ^~~~