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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cctype>
#include <ctime>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <string>
#include <map>
#include <iterator>
#define ll long long
#define mp make_pair
using namespace std;
const int M = 1000000007;
ll pot(ll A, ll B){
ll R = 1;
while (B){
if (B&1) R *= A;
R %= M;
A *= A; A %= M;
B >>= 1;
}
return R;
}
int n;
string s, h;
map <string, vector <string> > m;
vector <string> v[2];
map <string, int> vis;
bool inf = true;
int intq(string a){
if (isdigit(a[0])) return 1;
else return 0;
}
void dfs(string node, int c){
/*cout << node << " " << c << "\n";*/
if (c == 2) inf = false;
if (inf == false or vis[node] == 1) return;
vis[node] = 1;
for (int i = 0; i < m[node].size(); i++){
dfs(m[node][i], c + intq(m[node][i]));
}
return;
}
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 0; i < 2*n; i++){
cin >> s; v[i/n].push_back(s);
vis[s] = 0;
}
for (int i = 0; i < n; i++){
s = v[0][i]; h = v[1][i];
m[s].push_back(h);
m[h].push_back(s);
}
for (int i = 0; i < n; i++){
dfs(v[0][i], 0);
dfs(v[1][i], 0);
if (!inf) break;
}
if (inf) cout << "DA";
else cout << "NE";
return 0;
}
Compilation message (stderr)
zamjena.cpp: In function 'void dfs(std::__cxx11::string, int)':
zamjena.cpp:54:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < m[node].size(); i++){
~~^~~~~~~~~~~~~~~~
# | 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... |