#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PB push_back
#define POB pop_back
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define int int64_t
#define F first
#define S second
#define I insert
#define sqr(a) ((a) * (a))
#define P pop
#define max3(a, b, c) (max(a, max(b, c)))
#define max4(a, b, c, d) (max(max(a, b), max(c, d)))
#define min3(a, b, c) (min(a, min(b, c)))
#define min4(a, b, c, d) (min(min(a, b), min(c, d)))
#define MOD 1000000007
#define mod 998244353
int binpow(int a, int p, int m = MOD) {
int ans = 1;
while (p) {
if (p & 1) ans = ((ans % m) * (a % m)) % m;
a = sqr(a) % m;
p >>= 1;
}
return ans;
}
vector<vector<int>> adj2;
vector<int> typ;
int n, m, v;
bool dfs(int s, int pre) {
bool ans = false;
if (pre == n - 1) {
typ[s] = pre + 1;
return true;
}
for (auto x : adj2[s]) {
if (typ[x] == 0) {
ans |= dfs(x, pre + 1);
} else if (typ[x] == pre + 2)
ans = true;
}
if (ans) typ[s] = pre + 1;
return ans;
}
void solve() {
cin >> n >> m >> v;
vector<vector<int>> adj(m, vector<int>());
adj2.assign(m, vector<int>());
typ.assign(m, 0);
queue<int> q;
vector<int> tost(m, 0);
for (int i = 0; i < v; i++) {
int a, c;
char b;
cin >> a >> b >> c;
if (b == '=') {
adj[a - 1].PB(c - 1);
adj[c - 1].PB(a - 1);
}
if (b == '<') {
adj2[a - 1].PB(c - 1);
tost[c - 1]++;
}
if (b == '>') {
adj2[c - 1].PB(a - 1);
tost[a - 1]++;
}
}
for (int i = 0; i < m; i++) {
if (tost[i] == 0) dfs(i, 0);
}
vector<bool> vis(m, false);
for (int i = 0; i < m; i++) {
if (typ[i] != 0) {
q.push(i);
vis[i] = true;
}
}
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto x : adj[u]) {
if (vis[x]) continue;
typ[x] = typ[u];
vis[x] = true;
q.push(x);
}
}
for (int i = 0; i < m; i++) {
if (typ[i] == 0)
cout << '?' << endl;
else
cout << 'K' << typ[i] << endl;
}
}
int32_t main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
315 ms |
17712 KB |
Output is correct |
2 |
Correct |
293 ms |
17816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2058 ms |
1796 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2029 ms |
28756 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |