This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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(a == b)
return;
if(cati[a] < cati[b]) swap(a, b);
cati[a] += cati[b];
numere[a] += numere[b];
parent[b] = a;
}
int main() {
//ifstream cin(".in");
//ofstream cout(".out");
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[0] && s[0] <= '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[0] && s[0] <= '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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |