#include <bits/stdc++.h>
//#include<random>
using namespace std;
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("O3")*/
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")//for codeforces*/
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;
typedef map<ll, ll> mll;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int iINF=INT_MAX;
const ll INF=LLONG_MAX;
const ld PI=3.14159265358979323846;
ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);}
ll fpow(ll a,ll b,ll m) {
if(!b) return 1;
ll ans=fpow(a*a%m,b/2,m);
return (b%2?ans*a%m:ans);
}
ll inv(ll a,ll m) {return fpow(a,m-2,m);}
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define dbg(n) cerr<<#n<<": "<<n<<"\n";
#define optline cout<<"\n";
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define irep(i,m,n) for(ll i=m;i>=n;i--)
#define F first
#define S second
#define All(c) c.begin(), c.end()
#define pb push_back
#define eb emplace_back
//#define mp make_pair
#define uni(c) c.resize(distance(c.begin(), unique(c.begin(), c.end())))
#define unisort(c) sort(c.begin(), c.end());uni(c)
const int N=1e5+5;
vector<ll> G[N];
vector<string> a(N), b(N);
map<string, ll> mp;
bool vis[N];
ll id=0;
vector<ll> v;
bool isint(string s) {
for(char c:s) {
if(c<'0' || c>'9') return 0;
}
return 1;
}
void dfs(ll x) {
vis[x]=1;
for(int u:G[x]) {
if(!vis[u]) dfs(u);
}
}
signed main() {
memset(vis, false, sizeof(vis));
ll n;
cin>>n;
rep(i, n) {
string s;
cin>>a[i];
if(!mp.count(a[i])) {
mp[a[i]]=id++;
}
}
rep(i, n) {
cin>>b[i];
if(!mp.count(b[i])) {
mp[b[i]]=id++;
}
}
for(auto &p:mp) {
if(isint(p.F)) v.pb(p.S);
}
rep(i, n) {
G[mp[a[i]]].pb(mp[b[i]]);
G[mp[b[i]]].pb(mp[a[i]]);
}
for(ll x:v) {
if(!vis[x]) dfs(x);
else {
cout<<"NE\n";
return 0;
}
}
cout<<"DA\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8944 KB |
Output is correct |
2 |
Correct |
5 ms |
9036 KB |
Output is correct |
3 |
Correct |
4 ms |
9036 KB |
Output is correct |
4 |
Correct |
4 ms |
9044 KB |
Output is correct |
5 |
Correct |
5 ms |
8916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9012 KB |
Output is correct |
2 |
Correct |
5 ms |
9044 KB |
Output is correct |
3 |
Correct |
5 ms |
9040 KB |
Output is correct |
4 |
Correct |
5 ms |
8916 KB |
Output is correct |
5 |
Correct |
4 ms |
8916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8916 KB |
Output is correct |
2 |
Correct |
4 ms |
8916 KB |
Output is correct |
3 |
Correct |
4 ms |
8960 KB |
Output is correct |
4 |
Correct |
5 ms |
8916 KB |
Output is correct |
5 |
Correct |
5 ms |
8916 KB |
Output is correct |
6 |
Correct |
5 ms |
9032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9044 KB |
Output is correct |
2 |
Correct |
5 ms |
9044 KB |
Output is correct |
3 |
Correct |
10 ms |
9300 KB |
Output is correct |
4 |
Correct |
9 ms |
9308 KB |
Output is correct |
5 |
Correct |
10 ms |
9304 KB |
Output is correct |
6 |
Correct |
10 ms |
9248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
9728 KB |
Output is correct |
2 |
Correct |
39 ms |
10728 KB |
Output is correct |
3 |
Correct |
65 ms |
12124 KB |
Output is correct |
4 |
Correct |
82 ms |
12620 KB |
Output is correct |
5 |
Correct |
119 ms |
14648 KB |
Output is correct |
6 |
Correct |
95 ms |
12496 KB |
Output is correct |