#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 300007;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-6;
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;
map <string, string> p;
string a[M], b[M];
int n;
string root(string x){
while(x != p[x]){
p[x] = p[p[x]];
x = p[x];
}
return x;
}
void connect(string x, string y){
x = root(x); y = root(y);
if(x == y) return;
p[x] = y;
return;
}
bool is(string s) { return (s[0] >= '0' && s[0] <= '9'); }
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; ++i){
cin >> a[i];
p[a[i]] = a[i];
}
for(int i = 1; i <= n; ++i){
cin >> b[i];
p[b[i]] = b[i];
}
for(int i = 1; i <= n; ++i) connect(a[i], b[i]);
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
if(is(a[i]) && is(b[j]) && a[i] != b[j] && root(a[i]) == root(b[j])) cout << "NE\n", exit(0);
if(is(a[i]) && is(a[j]) && a[i] != a[j] && root(a[i]) == root(a[j])) cout << "NE\n", exit(0);
if(is(b[i]) && is(b[j]) && b[i] != b[j] && root(b[i]) == root(b[j])) cout << "NE\n", exit(0);
}
}
cout << "DA\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19012 KB |
Output is correct |
2 |
Correct |
10 ms |
19092 KB |
Output is correct |
3 |
Correct |
10 ms |
19104 KB |
Output is correct |
4 |
Correct |
10 ms |
19112 KB |
Output is correct |
5 |
Correct |
11 ms |
19028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19032 KB |
Output is correct |
3 |
Correct |
11 ms |
19112 KB |
Output is correct |
4 |
Correct |
12 ms |
19028 KB |
Output is correct |
5 |
Correct |
10 ms |
19028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19028 KB |
Output is correct |
2 |
Correct |
10 ms |
19028 KB |
Output is correct |
3 |
Correct |
9 ms |
19100 KB |
Output is correct |
4 |
Correct |
10 ms |
19108 KB |
Output is correct |
5 |
Correct |
10 ms |
19020 KB |
Output is correct |
6 |
Correct |
9 ms |
19028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
19112 KB |
Output is correct |
2 |
Correct |
43 ms |
19160 KB |
Output is correct |
3 |
Correct |
113 ms |
19348 KB |
Output is correct |
4 |
Correct |
21 ms |
19412 KB |
Output is correct |
5 |
Execution timed out |
1075 ms |
19412 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
361 ms |
19808 KB |
Output is correct |
2 |
Execution timed out |
1079 ms |
20700 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |