답안 #160662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
160662 2019-10-29T08:06:56 Z mraron Zamjena (COCI18_zamjena) C++14
70 / 70
191 ms 13348 KB
/*
ID: noszaly1
TASK: {TASK}
LANG: C++11               
*/

//Noszály Áron 10o Debreceni Fazekas Mihály Gimnázium

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

const int MAXN=200100;

int par[MAXN], sz[MAXN];

void init() {
	memset(par, -1, sizeof par);
	for(int i=0;i<MAXN;++i) sz[i]=1;
}

int get(int x) {
	if(par[x]==-1) return x;
	return par[x]=get(par[x]);
}

void merge(int x, int y) {
	int px=get(x), py=get(y);
	
	if(px==py) return ;
	
	if(sz[px]>sz[py]) swap(px, py);
	
	par[px]=py;
	sz[py]+=sz[px];
}




int main() {
	IO;
	init();
	bool ok=true;
	int n;
	cin>>n;
	vector<string> a(n), b(n);
	set<string> lst;
	
	for(int i=0;i<n;++i) {
		cin>>a[i];
		lst.insert(a[i]);
	}
	for(int i=0;i<n;++i) {
		cin>>b[i];
		lst.insert(b[i]);
	}
	
	map<string, int> conv;
	int ind=0;
	for(auto i:lst) {
		conv[i]=ind++;
		//cerr<<i<<": "<<ind<<"\n";
	}
	
	for(int i=0;i<n;++i) {
		if(get(conv[a[i]])!=get(conv[b[i]])){
			merge(conv[a[i]], conv[b[i]]);
		}
	}
	
	vector<int> volt(200001);
	for(auto i:lst) {
		if(!ok) break ;
		if(i[0]>='0' && i[0]<='9') {
			volt[get(conv[i])]++;
			ok&=volt[get(conv[i])]<=1;
		}
	}
	
	cout<<(ok?"DA":"NE")<<"\n";

	
	
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2684 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2808 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 4 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2808 KB Output is correct
2 Correct 5 ms 2808 KB Output is correct
3 Correct 9 ms 3192 KB Output is correct
4 Correct 10 ms 3320 KB Output is correct
5 Correct 11 ms 3324 KB Output is correct
6 Correct 14 ms 3192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 4344 KB Output is correct
2 Correct 53 ms 6264 KB Output is correct
3 Correct 87 ms 8668 KB Output is correct
4 Correct 105 ms 9760 KB Output is correct
5 Correct 191 ms 13348 KB Output is correct
6 Correct 126 ms 9484 KB Output is correct