# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
159691 | socho | Zamjena (COCI18_zamjena) | C++14 | 326 ms | 16348 KiB |
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"
using namespace std;
map<string, vector<string> > adj;
map<string, bool> vis;
bool isn(string s) {
char x = s[0];
if (x >= '0' && x <= '9') return true;
return false;
}
int dfsw(string s, string last) {
if (vis[s]) return 0;
int count = isn(s);
vis[s] = true;
// cout << "dfs: " << s << endl;
for (int i=0; i<adj[s].size(); i++) {
string other = adj[s][i];
// cout << " > " << other << endl;
if (other == last) continue;
if (other == s) continue;
if (vis[other]) continue;
count += dfsw(other, s);
}
return count;
}
int main() {
int n;
cin >> n;
string a1[n], a2[n];
for (int i=0; i<n; i++) cin >> a1[i];
for (int i=0; i<n; i++) cin >> a2[i];
for (int i=0; i<n; i++) {
string a = a1[i], b = a2[i];
if (a == b) continue;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int i=0; i<n; i++) {
string a = a1[i];
if (!vis[a]) {
int re = dfsw(a, "");
// cout << "RES: " << a << ' ' << re << endl;
if (re > 1) {
cout << "NE" << endl;
exit(0);
}
}
}
cout << "DA" << endl;
exit(0);
}
Compilation message (stderr)
# | 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... |