#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6484 KB |
Output is correct |
2 |
Correct |
4 ms |
6484 KB |
Output is correct |
3 |
Correct |
4 ms |
6484 KB |
Output is correct |
4 |
Correct |
3 ms |
6592 KB |
Output is correct |
5 |
Correct |
4 ms |
6484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
3 ms |
6484 KB |
Output is correct |
3 |
Correct |
4 ms |
6592 KB |
Output is correct |
4 |
Correct |
4 ms |
6588 KB |
Output is correct |
5 |
Correct |
3 ms |
6484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
5 ms |
6484 KB |
Output is correct |
3 |
Correct |
3 ms |
6592 KB |
Output is correct |
4 |
Correct |
4 ms |
6596 KB |
Output is correct |
5 |
Correct |
4 ms |
6484 KB |
Output is correct |
6 |
Correct |
4 ms |
6596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6612 KB |
Output is correct |
2 |
Correct |
5 ms |
6612 KB |
Output is correct |
3 |
Correct |
8 ms |
6736 KB |
Output is correct |
4 |
Correct |
7 ms |
6996 KB |
Output is correct |
5 |
Correct |
7 ms |
6740 KB |
Output is correct |
6 |
Correct |
6 ms |
6740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
7104 KB |
Output is correct |
2 |
Correct |
33 ms |
7944 KB |
Output is correct |
3 |
Correct |
44 ms |
9000 KB |
Output is correct |
4 |
Correct |
77 ms |
9252 KB |
Output is correct |
5 |
Correct |
102 ms |
11072 KB |
Output is correct |
6 |
Correct |
61 ms |
8864 KB |
Output is correct |