# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
107185 |
2019-04-22T11:59:20 Z |
WLZ |
Zamjena (COCI18_zamjena) |
C++14 |
|
98 ms |
66560 KB |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
class DSU {
private:
vector<int> p, rank, sz;
public:
DSU(int n) {
p.assign(n, -1);
rank.assign(n, 0);
sz.assign(n, 0);
for (int i = 0; i < 1000; i++) {
sz[i] = 1;
}
}
int root(int x) {
if (p[x] < 0) {
return x;
}
return (p[x] == root(p[x]));
}
int sameSet(int x, int y) {
return (root(x) == root(y));
}
void connect(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (rank[x] > rank[y]) {
p[y] = x;
sz[x] += sz[y];
} else {
p[x] = y;
if (rank[x] == rank[y]) {
rank[y]++;
}
sz[y] += sz[x];
}
}
}
int setSize(int x) {
return sz[root(x)];
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<string> a(n), b(n);
map<string, int> mp;
int cur = 1000;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (!isdigit(a[i][0]) && !mp.count(a[i])) {
mp[a[i]] = cur++;
}
}
for (int i = 0; i < n; i++) {
cin >> b[i];
if (!isdigit(b[i][0]) && !mp.count(b[i])) {
mp[b[i]] = cur++;
}
}
DSU dsu((int) 1e5);
for (int i = 0; i < n; i++) {
int tmpa, tmpb;
if (isdigit(a[i][0])) {
tmpa = stoi(a[i]);
} else {
tmpa = mp[a[i]];
}
if (isdigit(b[i][0])) {
tmpb = stoi(b[i]);
} else {
tmpb = mp[b[i]];
}
dsu.connect(tmpa, tmpb);
}
for (int i = 0; i < (int) 1e5; i++) {
if (dsu.setSize(i) > 1) {
cout << "NE\n";
return 0;
}
}
cout << "DA\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1536 KB |
Output is correct |
2 |
Correct |
3 ms |
1536 KB |
Output is correct |
3 |
Correct |
3 ms |
1536 KB |
Output is correct |
4 |
Correct |
15 ms |
1664 KB |
Output is correct |
5 |
Correct |
4 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
1536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
69 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
98 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |