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 pb push_back
#define whole(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = (int)1e5 + 7;
const int INF = (int)1e9 + 7;
const ll linf = (ll)1e18 + 1;
string a[N], b[N];
bool used[N];
string val[N], ans = "-1";
vector<int> g[N];
map<string, int> was;
bool dfs(int v) {
used[v] = 1;
if (ans == "-1" && ('0' <= val[v][0] && val[v][0] <= '9')) ans = val[v];
if (ans != "-1" && ('0' <= val[v][0] && val[v][0] <= '9') && ans != val[v]) return false;
for (int to : g[v]) {
if (!used[to]) {
if (!dfs(to)) return false;
}
}
return true;
}
int main() {
int n; cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) cin >> b[i];
int pos = 0;
for (int i = 1; i <= n; ++i) {
int v = -1;
if (!was.count(a[i])) v = ++pos, was[a[i]] = pos;
else v = was[a[i]];
int to = -1;
if (!was.count(b[i])) to = ++pos, was[b[i]] = pos;
else to = was[b[i]];
val[v] = a[i], val[to] = b[i];
g[v].pb(to);
g[to].pb(v);
}
for (int i = 1; i <= pos; ++i) {
if (!used[i]) {
ans = "-1";
if (!dfs(i)) return cout << "NE\n", 0;
}
}
cout << "DA\n";
return 0;
}
/*
5
x 3 x y 3
x y 2 z 3
*/
# | 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... |