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;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pi;
typedef long long int lint;
const int inf = 0x3f3f3f3f;
const int maxn = 50000 + 10;
int n;
string a[maxn], b[maxn];
map< string, vector< int > > c, d;
map< string, bool > memo;
map< string, vector< string > > isti;
bool ok = 1;
bool isNumber(string t) {
if(t[0] >= '0' and t[0] <= '9') return 1;
return 0;
}
void dfs(string word, string number) {
if(!ok) return;
if(memo[word]) return;
memo[word] = 1;
for(int i = 0; i < isti[word].size(); ++i) {
if(isNumber(isti[word][i]) and isti[word][i] != number) ok = 0;
if(!ok) return;
if(memo[isti[word][i]]) continue;
dfs(isti[word][i], number);
}
}
int main ()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 0; i < n; ++i) {
cin >> a[i];
if(not isNumber(a[i]))
c[a[i]].pb(i);
}
for(int i = 0; i < n; ++i) {
cin >> b[i];
if(not isNumber(b[i]))
d[b[i]].pb(i);
}
for(int i = 0; i < n; ++i) {
isti[a[i]].pb(b[i]);
isti[b[i]].pb(a[i]);
}
for(int i = 0; i < n; ++i) {
if(not memo[a[i]] and isNumber(a[i])) {
dfs(a[i], a[i]);
if(!ok)
return cout << "NE", 0;
}
if(not memo[b[i]] and isNumber(b[i])) {
dfs(b[i], b[i]);
if(!ok)
return cout << "NE", 0;
}
}
cout << "DA";
return 0;
}
Compilation message (stderr)
zamjena.cpp: In function 'void dfs(std::__cxx11::string, std::__cxx11::string)':
zamjena.cpp:29:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < isti[word].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... |