# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
583544 | Markomafko972 | KOVANICE (COI15_kovanice) | C++14 | 232 ms | 30524 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
int a[300005];
int b[300005];
char w[300005];
int prt[300005];
vector<int> v[300005];
int dub[300005];
int sol[300005];
int find(int x) {
if (prt[x] == x) return x;
return prt[x] = find(prt[x]);
}
void unija(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return;
prt[y] = x;
}
int dfs(int x) {
if (dub[x] > 0) return dub[x];
for (int i = 0; i < v[x].size(); i++) {
dub[x] = max(dub[x], dfs(v[x][i]));
}
dub[x]++;
return dub[x];
}
void rek(int x) {
sol[x] = dub[x];
for (int i = 0; i < v[x].size(); i++) {
if (sol[v[x][i]] == 0 && dub[v[x][i]]+1 == dub[x]) rek(v[x][i]);
}
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> q;
for (int i = 1; i <= m; i++) prt[i] = i;
for (int i = 0; i < q; i++) {
cin >> a[i] >> w[i] >> b[i];
if (w[i] == '=') unija(a[i], b[i]);
}
for (int i = 0; i < q; i++) {
int poc = find(a[i]), kr = find(b[i]);
if (w[i] == '>') v[poc].push_back(kr);
else if (w[i] == '<') v[kr].push_back(poc);
}
for (int i = 1; i <= m; i++) {
if (dub[find(i)] == 0) dfs(find(i));
}
for (int i = 1; i <= m; i++) {
if (sol[find(i)] == 0 && dub[find(i)] == n) rek(find(i));
}
for (int i = 1; i <= m; i++) {
if (sol[find(i)] == 0) cout << "?\n";
else cout << "K" << sol[find(i)] << "\n";
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |