# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
241494 | marlicu | KOVANICE (COI15_kovanice) | C++14 | 139 ms | 17656 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;
const int MAXN = 3e5 + 5;
int n, m, v;
int pripada[MAXN];
vector <int> veze[MAXN];
bool ispisan[MAXN];
int vrsta[MAXN];
void init() {
for (int i = 1; i <= m; i++) {
pripada[i] = i;
}
}
void ispis() {
for (int i = 1; i <= m; i++) {
cout << pripada[i] << " ";
}
cout << '\n';
memset(ispisan, 0, sizeof(ispisan));
for (int i = 1; i <= m; i++) {
if (ispisan[i]) continue;
cout << i << " ";
int t = i;
while (veze[t].size()) {
cout << veze[t][0] << " ";
t = veze[t][0];
ispisan[t] = true;
}
cout << '\n';
ispisan[i] = true;
}
}
void konacan_ispis() {
int x;
for (int i = 1; i <= m; i++) {
x = pripada[i];
if (!vrsta[x]) cout << "?\n";
else cout << "K" << vrsta[x] << "\n";
}
}
void vaganje() {
string s;
cin >> s;
int a, b = 0;
char znak;
unsigned t = -1;
while (++t < s.size()) {
if (s[t] == '=' || s[t] == '<') {
znak = s[t];
a = b;
b = 0;
}
else {
b *= 10;
b += (s[t] - '0');
}
}
//cout << a << " " << znak << " " << b << '\n';
a = pripada[a];
b = pripada[b];
if (znak == '=') {
if (a < b) pripada[b] = a;
else pripada[a] = b;
}
else {
veze[a].push_back(b);
}
//ispis();
}
void odredivanje() {
vector <int> niz;
memset(ispisan, 0, sizeof(ispisan));
for (int i = 1; i <= m; i++) {
int t = pripada[i];
if (ispisan[t]) continue;
ispisan[t] = true;
niz.clear();
niz.push_back(t);
while (veze[t].size()) {
t = veze[t][0];
ispisan[t] = true;
niz.push_back(t);
}
/*
cout << niz.size() << " : ";
for (auto x : niz) {
cout << x << " ";
}
cout << '\n';
*/
if (niz.size() == n) {
for (int j = 0; j < n; j++) {
vrsta[niz[j]] = j + 1;
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m >> v;
init();
for (int i = 0; i < v; i++) {
vaganje();
}
odredivanje();
konacan_ispis();
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... |