# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1025733 |
2024-07-17T09:26:23 Z |
vjudge1 |
Zamjena (COCI18_zamjena) |
C++17 |
|
166 ms |
11980 KB |
#include <bits/stdc++.h>
using namespace std;
map<string, string> parent;
map<string, int> sz;
string Find(string x) {
if (parent[x]==x)
return x;
return parent[x]=Find(parent[x]);
}
bool Union(string a, string b) {
a=Find(a), b=Find(b);
if (a[0]-'0'<=9&&b[0]-'0'<=9)
return a==b;
if (a[0]-'0'<=9) {
parent[b]=a;
sz[a]+=sz[b];
return 1;
}
if (b[0]-'0'<=9) {
parent[a]=b;
sz[b]+=sz[a];
return 1;
}
if (a==b) return 1;
if (sz[a]<sz[b])
swap(a,b);
sz[a]+=sz[b];
parent[b]=a;
return 1;
}
int main()
{
int n;
cin >> n;
string a[n], b[n];
for (int i=0;i<n;i++) {
cin >> a[i];
parent[a[i]]=a[i];
sz[a[i]]=1;
}
for (int i=0;i<n;i++) {
cin >> b[i];
parent[b[i]]=b[i];
sz[b[i]]=1;
}
for (int i=0;i<n;i++) {
if (!Union(a[i], b[i])) {
cout << "NE";
return 0;
}
}
cout << "DA";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
860 KB |
Output is correct |
4 |
Correct |
6 ms |
1116 KB |
Output is correct |
5 |
Correct |
7 ms |
1116 KB |
Output is correct |
6 |
Correct |
6 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
2136 KB |
Output is correct |
2 |
Correct |
50 ms |
4184 KB |
Output is correct |
3 |
Correct |
80 ms |
6816 KB |
Output is correct |
4 |
Correct |
75 ms |
7744 KB |
Output is correct |
5 |
Correct |
166 ms |
11980 KB |
Output is correct |
6 |
Correct |
129 ms |
7260 KB |
Output is correct |