답안 #1026748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1026748 2024-07-18T10:28:53 Z kkkkkkkk Zamjena (COCI18_zamjena) C++14
70 / 70
170 ms 12324 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 5 ms 1040 KB Output is correct
4 Correct 6 ms 1116 KB Output is correct
5 Correct 6 ms 1116 KB Output is correct
6 Correct 5 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 2200 KB Output is correct
2 Correct 53 ms 4288 KB Output is correct
3 Correct 100 ms 6900 KB Output is correct
4 Correct 81 ms 8020 KB Output is correct
5 Correct 170 ms 12324 KB Output is correct
6 Correct 128 ms 7764 KB Output is correct