# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100383 | cvele | Zamjena (COCI18_zamjena) | C++14 | 158 ms | 11128 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 <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
using namespace std;
const int N = 100005;
int n;
string a[N], b[N];
int cnt = 1;
int p[N];
int what[N];
map <string, int> id;
int fs(int u) {
return (p[u] == u ? u : p[u] = fs(p[u]));
}
void join(int x, int y) {
int aa = fs(x), bb = fs(y);
if (aa == bb) return;
if (what[aa] && what[bb] && (what[aa] != what[bb])) {
cout << "NE" << endl;
exit(0);
}
if (!what[aa]) {
p[aa] = bb;
} else {
p[bb] = aa;
}
}
int tonum(string a) {
int ans = 0;
for (int i = 0; i < a.size(); i++) {
ans = ans * 10 + (a[i] - '0');
}
return ans;
}
int main() {
cin >> n;
for (int i = 0; i < N; i++) p[i] = i;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (!id[a[i]]) {
id[a[i]] = cnt++;
}
if (isdigit(a[i][0])) {
what[id[a[i]]] = tonum(a[i]);
}
}
for (int i = 0; i < n; i++) {
cin >> b[i];
if (!id[b[i]]) {
id[b[i]] = cnt++;
}
if (isdigit(b[i][0])) {
what[id[b[i]]] = tonum(b[i]);
}
}
for (int i = 0; i < n; i++) {
join(id[a[i]], id[b[i]]);
}
cout << "DA" << endl;
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |