제출 #639886

#제출 시각아이디문제언어결과실행 시간메모리
639886Vladth11Zamjena (COCI18_zamjena)C++14
0 / 70
12 ms13852 KiB
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long double, pii> muchie;

const ll NMAX = 100001;
const ll VMAX = 101;
const ll INF = 2e9;
const ll MOD = 1000000007;
const ll BLOCK = 447;
const ll base = 117;
const ll nr_of_bits = 24;
const ll inv2 = 500000004;

map <string, int> mp;

bool isNumar[NMAX];
string a[NMAX], b[NMAX];

int cnt = 0;
int parent[NMAX];
int cati[NMAX];
int numere[NMAX];

int root(int x){
    if(parent[x] == x)
        return x;
    return parent[x] = root(parent[x]);
}

void merge(int a, int b){
    a = root(a);
    b = root(b);
    if(cati[a] < cati[b]) swap(a, b);
    cati[a] += cati[b];
    numere[a] += numere[b];
    parent[b] = a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, i;
    cin >> n;
    for(i = 1; i <= n; i++){
        string s;
        cin >> s;
        if(mp.find(s) == mp.end()){
            mp[s] = ++cnt;
        }
        if('0' <= s[i] && s[i] <= '9'){
            isNumar[mp[s]] = 1;
        }
        a[i] = s;
    }
    for(i = 1; i <= n; i++){
        string s;
        cin >> s;
        if(mp.find(s) == mp.end()){
            mp[s] = ++cnt;
        }
        if('0' <= s[i] && s[i] <= '9'){
            isNumar[mp[s]] = 1;
        }
        b[i] = s;
    }
    for(i = 1; i <= cnt; i++){
        parent[i] = i;
        cati[i] = 1;
        numere[i] = isNumar[i];
    }
    for(i = 1; i <= n; i++){
        merge(mp[a[i]], mp[b[i]]);
    }
    int ok = 1;
    for(i = 1; i <= cnt; i++){
        if(numere[i] > 1){
            ok = 0;
        }
    }
    if(ok) cout << "DA";
    else cout << "NE";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...