# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
390179 | ioi | Zamjena (COCI18_zamjena) | C++14 | 373 ms | 20156 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;
const int N = 50001;
vector<string> g[N];
map<string , int > l;
map<string , int > mp ;
bool vis[N];
int nm ;
bool ntok = false;
map<int , string> aks ;
void dfs(int node){
//cout << node << " " << nm << endl;
vis[node] = true ;
if(mp[aks[node]] && mp[aks[node]] != nm)ntok = true ;
if(ntok)return ;
for(auto &it : g[node]){
if(vis[l[it]] == false){
dfs(l[it]);
}
if(ntok)return ;
}
}
int main()
{
int n ;
cin >> n ;
int idx = 0 ;
string a[n] , a2[n];
for(int i = 0 ; i < n ; i ++)cin >> a[i];
for(int i = 0 ; i < n ; i ++)cin >> a2[i];
vector<pair<string , string> > e ;
for(int i = 0 ; i < n ; i ++){
char c = a[i][0] , c2 = a2[i][0];
if(c < 97){
if(c2 < 97){
if(c != c2){
cout << "NE";
return 0 ;
}
}
else {
if(mp.count(a2[i]) && mp[a2[i]] != stoi(a[i])){
cout << "NE";
return 0;
}
else{
mp[a2[i]] = stoi(a[i]) ;
if(!l.count(a2[i]))l[a2[i]] = idx ++;
aks[l[a2[i]]] = a2[i];
}
}
}
else {
if(c2 < 97){
if(mp.count(a[i]) && mp[a[i]] != stoi(a2[i])){
cout << "NE";
return 0;
}
else {
mp[a[i]] = stoi(a2[i]) ;
if(!l.count(a[i]))l[a[i]] = idx ++ ;
aks[l[a[i]]] = a[i];
}
}
else {
if(!l.count(a[i]))l[a[i]] = idx ++ ;
if(!l.count(a2[i]))l[a2[i]] = idx ++ ;
aks[l[a[i]]] = a[i];
aks[l[a2[i]]] = a2[i];
g[l[a[i]]].push_back(a2[i]);
g[l[a2[i]]].push_back(a[i]);
}
}
}
// cout << mp[aks[1]] << "\n\n\n";
for(int i = 0 ; i < idx; i ++){
if(!vis[i] && mp[aks[i]])
nm = mp[aks[i]] , dfs(i);
if(ntok){
cout << "NE";
return 0;
}
}
cout << "DA";
}
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... |