# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1025603 |
2024-07-17T08:04:36 Z |
vjudge1 |
Zamjena (COCI18_zamjena) |
C++17 |
|
190 ms |
12232 KB |
#include <bits/stdc++.h>
using namespace std;
int MAX_N=100000;
map<string, string>p;
map<string, int>sz;
string Find(string i)
{
if(p[i]==i)
{
return i;
}
return p[i]=Find(p[i]);
}
bool Union(string a, string b)
{
a=Find(a);
b=Find(b);
if(isdigit(a[0]) && isdigit(b[0]))
{
if(a!=b)
return false;
else
return 1;
}
if(isdigit(a[0]))
{
p[b]=a;
sz[a]+=sz[b];
return 1;
}
if(isdigit(b[0]))
{
p[a]=b;
sz[b]+=sz[a];
return 1;
}
if(a!=b)
{
if(sz[a]>sz[b])
{
swap(a, b);
}
p[a]=b;
sz[b]+=sz[a];
}
return 1;
}
int main()
{
int n;
cin>>n;
string a[n], b[n];
for(int i=0; i<n; i++)
{
cin>>a[i];
p[a[i]]=a[i];
sz[a[i]]=1;
}
for(int i=0; i<n; i++)
{
cin>>b[i];
p[b[i]]=b[i];
sz[a[i]]=1;
}
bool kiki=0;
for(int i=0; i<n; i++)
{
if(!Union(a[i], b[i]))
{
kiki=1;
}
}
if(kiki)
{
cout<<"NE";
return 0;
}
else
{
cout<<"DA";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
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 |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
412 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 |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
7 ms |
860 KB |
Output is correct |
4 |
Correct |
6 ms |
1012 KB |
Output is correct |
5 |
Correct |
6 ms |
1112 KB |
Output is correct |
6 |
Correct |
6 ms |
956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
2128 KB |
Output is correct |
2 |
Correct |
56 ms |
4180 KB |
Output is correct |
3 |
Correct |
104 ms |
6888 KB |
Output is correct |
4 |
Correct |
109 ms |
8020 KB |
Output is correct |
5 |
Correct |
190 ms |
12232 KB |
Output is correct |
6 |
Correct |
137 ms |
7616 KB |
Output is correct |