#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;
#define MAXN 300005
vector<int> eq[MAXN];
int n, m, k;
vector<int> adjList[MAXN];
int counts[MAXN];
int compress[MAXN];
int ans[MAXN];
void fill(int src, int val) {
compress[src] = val;
for (auto i : eq[src]) {
if (compress[i] == -1) {
fill(i, val);
}
}
}
void dfs(int src, int depth) {
for (auto i : adjList[src]) {
if (ans[compress[i]] == -1) {
dfs(i, depth + 1);
}
}
if (depth == n) {
ans[compress[src]] = 1;
return;
}
for (auto i : adjList[src]) {
if (ans[compress[i]] != -1) {
ans[compress[src]] = ans[compress[i]] + 1;
return;
}
}
}
int main() {
cin >> n >> m >> k;
for (int i = 0; i <= m; i++) {
counts[i] = 0;
compress[i] = -1;
ans[i] = -1;
}
for (int i = 0; i < k; i++) {
string s;
cin >> s;
int node1 = s[0] - 48;
int node2 = s[2] - 48;
if (s[1] == '=') {
eq[node1].push_back(node2);
eq[node2].push_back(node1);
continue;
}
if (s[1] == '<') {
swap(node1, node2);
}
adjList[node1].push_back(node2);
counts[node2]++;
}
int counter = 1;
for (int i = 1; i <= m; i++) {
if (compress[i] == -1) {
fill(i, counter);
counter++;
}
}
for (int i = 1; i <= m; i++) {
if (counts[i] == 0) {
dfs(i, 1);
}
}
for (int i = 1; i <= m; i++) {
cout << "K";
if (ans[compress[i]] != -1) {
cout << ans[compress[i]] << endl;
}
else {
cout << "?" << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
14464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
536 ms |
19316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
15864 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
893 ms |
24316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |