# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
728745 | Cris_MCG | Zamjena (COCI18_zamjena) | C++17 | 9 ms | 2448 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>
#define int long long
using namespace std;
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//ifstream fin; fin.open("Copia Copia b.txt");
int n;
cin >> n;
pair<string, string> p[n];
vector<int> pos;
queue<string> v;
map<string, vector<string>> mapa;
map<string, string> val;
map<int, bool> ya;
for(int i = 0; i < n; i++) {
string s;
cin >> s;
if(s[0] - '0' >= 1 && s[0] - '0' <= 9) {
p[i].first = s;
pos.push_back(i);
ya[i] = 1;
}
else
p[i].first = s;
}
for(int i = 0; i < n; i++) {
string s;
cin >> s;
if(s[0] - '0' >= 1 && s[0] - '0' <= 9) {
p[i].second = s;
if(!ya[i])
pos.push_back(i);
}
else
p[i].second = s;
}
for(int i = 0; i < n; i++) {
if(p[i].first[0] > 60 && p[i].second[0] > 60) {
mapa[p[i].first].push_back(p[i].second);
if(p[i].first != p[i].second)
mapa[p[i].second].push_back(p[i].first);
}
}
bool b = 0;
for(int i = 0; i < pos.size() && !b; i++) {
int x = pos[i];
if(p[x].first[0] - '0' >= 1 && p[x].first[0] - '0' <= 9 && p[x].second[0] - '0' >= 0 && p[x].second[0] - '0' <= 9) {
if(p[x].first != p[x].second)
b = 1;
continue;
}
else if(p[x].second[0] > 60) {
val[p[x].second] = p[x].first;
v.push(p[x].second);
continue;
}
else if(p[x].first[0] > 60) {
val[p[x].first] = p[x].second;
v.push(p[x].first);
continue;
}
}
if(b) {
cout << "NO" << '\n';
return 0;
}
while(!v.empty() && !b) {
string aux = v.front();
v.pop();
string va = val[aux];
for(int i = 0; i < mapa[aux].size(); i++) {
if(val[mapa[aux][i]] == "") {
v.push(mapa[aux][i]);
val[mapa[aux][i]] = va;
}
else {
if(val[mapa[aux][i]] != va)
b = 1;
}
}
}
if(!b)
cout << "YES" << '\n';
else
cout << "NO" << '\n';
return 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... |