Submission #1025597

# Submission time Handle Problem Language Result Execution time Memory
1025597 2024-07-17T07:57:52 Z vjudge1 Zamjena (COCI18_zamjena) C++17
0 / 70
46 ms 4180 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 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Incorrect 2 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2136 KB Output is correct
2 Incorrect 46 ms 4180 KB Output isn't correct
3 Halted 0 ms 0 KB -