이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
unordered_map <string, int> mp;
unordered_map <string, vector <string> > v;
string arr1[100007],arr2[100007];
bool ch (string s)
{
if ((int)(s[0]-'0') <= 10)return 1;
return 0;
}
int toint (string s)
{
int t=1,sum=0;
for (int i=s.size()-1; i>=0; i--)
{
sum+=(s[i]-'0')*t;
t*=10;
}
return sum;
}
void dfs (string u, int x)
{
mp[u] = x;
for (auto w : v[u])
if (!mp.count (w))
dfs (w, x);
}
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)cin>>arr1[i];
for (int i = 0; i < n; i++)cin>>arr2[i];
for (int j = 1; j <= 10; j++)
{
for (int i = 0; i < n; i++)
{
if (ch (arr1[i]))
{
if (ch (arr2[i]))
{
if (arr1[i] != arr2[i])
{
cout << "NE" ;
return 0;
}
}
else
{
int x = toint (arr1[i]);
if (!mp.count (arr2[i]))
{
dfs (arr2[i], x);
}
if (!mp.count (arr2[i])||mp[arr2[i]] == x)
mp[arr2[i]] = x;
else
{
cout << "NE" ;
return 0;
}
}
}
else
{
if (ch (arr2[i]))
{
int x = toint (arr2[i]);
if (!mp.count (arr1[i]))
{
dfs (arr1[i], x);
}
if (!mp.count (arr1[i])||mp[arr1[i]] == x)
mp[arr1[i]] = x;
else
{
cout << "NE" ;
return 0;
}
}
else
{
if (mp.count (arr1[i]))
{
if (mp.count (arr2[i]))
{
if (mp[arr1[i]] != mp[arr2[i]])
{
cout << "NE" ;
return 0;
}
}
else
{
mp[arr2[i]] = mp[arr1[i]];
}
}
else if (mp.count (arr2[i]))
{
mp[arr1[i]] = mp[arr2[i]];
}
v[arr1[i]].push_back (arr2[i]);
v[arr2[i]].push_back (arr1[i]);
}
}
}
}
cout << "DA" ;
return 0;
}
# | 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... |