이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <string>
using namespace std;
int n;
map <string, string> m;
vector <string> a, b;
bool is_number(string s) {
return (s[0] >= '0' && s[0] <= '9');
}
string find(string s) {
if (!m.count(s)) return s;
if (is_number(s)) return s;
return m[s] = find(m[s]);
}
bool cmp(string x, string y){
x = find(x);
y = find(y);
if (x == y) return true;
bool nx = is_number(x), ny = is_number(y);
if (nx && ny) return x == y;
else if (nx && !ny) m[y] = x;
else if (!nx && ny) m[x] = y;
else m[x] = y;
return true;
}
bool solve() {
for (int i = 1; i <= n; i++)
if (!cmp(a[i], b[i])) return false;
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
a = b = vector <string>(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
cout << (solve() ? "DA" : "NE") << '\n';
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... |