Buggy python submission (verdict: Time Limit Exceeded):
# マージO(n)かかっちゃう
class union_find(object):
 	"""union-find tree"""
 	def __init__(self, length):
 		self.length = length
 		self.unionnumber=0
 		self.unionlist=[[]]
 		self.num=list(-1 for i in range(length))

 	def unite(self,i,j):
 		if self.num[i]==-1:
 			if self.num[j]==-1:
 				self.unionlist[self.unionnumber].extend([i,j])
 				self.num[i]=self.unionnumber
 				self.num[j]=self.unionnumber
 				self.unionnumber+=1
 				self.unionlist.append([])
 			else:
 				tmp=i 
 				i=j 
 				j=tmp 
 		if self.num[i]!=-1:
 			if self.num[j]!=-1:
 				if self.num[i]==self.num[j]:
 					pass
 				else:
 					self.unionlist[self.num[i]].extend(self.unionlist[self.num[j]])
 					tmp=self.num[j]
 					for k in self.unionlist[self.num[j]]:
 						self.num[k]=self.num[i]
 					self.unionlist[tmp]="del"
 			else:
 				self.num[j]=self.num[i]
 				self.unionlist[self.num[i]].append(j)

 	def same(self,i,j):
 		if self.num[i]==-1 or self.num[j]==-1:
 			return(False)
 		else:
 			return(self.num[i]==self.num[j])


N,K,L=list(map(int,input().split()))
road=union_find(N)
rail=union_find(N)

for i in range(K):
	a=list(map(int,input().split()))
	road.unite(a[0]-1,a[1]-1)

for i in range(L):
	a=list(map(int,input().split()))
	rail.unite(a[0]-1,a[1]-1)

res=[0 for i in range(N)]
for i in range(N):
	if res[i]==0:
		n=road.num[i]
		A=road.unionlist[n]
		m=rail.num[i]
		B=set(rail.unionlist[m]).intersection(A)
		l=len(B)
		if l==0:
			B=[i]
			l=1
		for j in B:
			res[j]=l

for i in res:
	print(i,end=" ")
print("")
















Fixed submission:
# マージO(n)かかっちゃう
class union_find:
	def __init__(self, size):
		# 負の値はルート (集合の代表) で集合の個数
		# 正の値は次の要素を表す
		self.size=size
		self.table = [-1 for _ in range(size)]
		self.num=[0 for i in range(size)]

	# 集合の代表を求める
	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			# 経路の圧縮
			self.table[x] = self.find(self.table[x])
			return(self.table[x])

	# 併合
	def unite(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] <= self.table[s2]:
				# 小さいほうが個数が多い
				self.table[s1] += self.table[s2]
				self.table[s2] = s1
			else:
				self.table[s2] += self.table[s1]
				self.table[s1] = s2
			return(True)
		return(False)

	def definite(self):
		for i in range(self.size):
			self.num[i]=self.find(i)
		return(True)


N,K,L=list(map(int,input().split()))
road=union_find(N)
rail=union_find(N)

for i in range(K):
	a=list(map(int,input().split()))
	road.unite(a[0]-1,a[1]-1)

for i in range(L):
	a=list(map(int,input().split()))
	rail.unite(a[0]-1,a[1]-1)

road.definite()
rail.definite()

dic={}
# print(road.num,rail.num)

for i in range(N):
	key=str(road.num[i])+":"+str(rail.num[i])
	if key in dic:
		dic[key].append(i)
	else:
		dic[key]=[i]

# print(dic)
res=[0 for i in range(N)]
for i in dic.values():
	l=len(i)
	for j in i:
		res[j]=l

for i in res:
	print(i,end=" ")
print("")

Buggy python submission (verdict: Time Limit Exceeded):
# マージO(n)かかっちゃう
class union_find(object):
 	"""union-find tree"""
 	def __init__(self, length):
 		self.length = length
 		self.unionnumber=0
 		self.unionlist=[[]]
 		self.num=list(-1 for i in range(length))

 	def unite(self,i,j):
 		if self.num[i]==-1:
 			if self.num[j]==-1:
 				self.unionlist[self.unionnumber].extend([i,j])
 				self.num[i]=self.unionnumber
 				self.num[j]=self.unionnumber
 				self.unionnumber+=1
 				self.unionlist.append([])
 			else:
 				tmp=i 
 				i=j 
 				j=tmp 
 		if self.num[i]!=-1:
 			if self.num[j]!=-1:
 				if self.num[i]==self.num[j]:
 					pass
 				else:
 					self.unionlist[self.num[i]].extend(self.unionlist[self.num[j]])
 					tmp=self.num[j]
 					for k in self.unionlist[self.num[j]]:
 						self.num[k]=self.num[i]
 					self.unionlist[tmp]="del"
 			else:
 				self.num[j]=self.num[i]
 				self.unionlist[self.num[i]].append(j)

 	def same(self,i,j):
 		if self.num[i]==-1 or self.num[j]==-1:
 			return(False)
 		else:
 			return(self.num[i]==self.num[j])


N,K,L=list(map(int,input().split()))
road=union_find(N)
rail=union_find(N)

for i in range(K):
	a=list(map(int,input().split()))
	road.unite(a[0]-1,a[1]-1)

for i in range(L):
	a=list(map(int,input().split()))
	rail.unite(a[0]-1,a[1]-1)

res=[0 for i in range(N)]
for i in range(N):
	if res[i]==0:
		n=road.num[i]
		A=road.unionlist[n]
		m=rail.num[i]
		B=set(rail.unionlist[m]).intersection(A)
		l=len(B)
		if l==0:
			B=[i]
			l=1
		for j in B:
			res[j]=l

for i in res:
	print(i,end=" ")
print("")
















Fixed submission:
# マージO(n)かかっちゃう
class union_find:
	def __init__(self, size):
		# 負の値はルート (集合の代表) で集合の個数
		# 正の値は次の要素を表す
		self.size=size
		self.table = [-1 for _ in range(size)]
		self.num=[0 for i in range(size)]

	# 集合の代表を求める
	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			# 経路の圧縮
			self.table[x] = self.find(self.table[x])
			return(self.table[x])

	# 併合
	def unite(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] <= self.table[s2]:
				# 小さいほうが個数が多い
				self.table[s1] += self.table[s2]
				self.table[s2] = s1
			else:
				self.table[s2] += self.table[s1]
				self.table[s1] = s2
			return(True)
		return(False)

	def definite(self):
		for i in range(self.size):
			self.num[i]=self.find(i)
		return(True)


N,K,L=list(map(int,input().split()))
road=union_find(N)
rail=union_find(N)

for i in range(K):
	a=list(map(int,input().split()))
	road.unite(a[0]-1,a[1]-1)

for i in range(L):
	a=list(map(int,input().split()))
	rail.unite(a[0]-1,a[1]-1)

road.definite()
rail.definite()

dic={}
# print(road.num,rail.num)

for i in range(N):
	key=str(road.num[i])+":"+str(rail.num[i])
	if key in dic:
		dic[key].append(i)
	else:
		dic[key]=[i]

# print(dic)
res=[0 for i in range(N)]
for i in dic.values():
	l=len(i)
	for j in i:
		res[j]=l

for i in res:
	print(i,end=" ")
print("")

Buggy python submission (verdict: Time Limit Exceeded):
# マージO(n)かかっちゃう
class union_find(object):
 	"""union-find tree"""
 	def __init__(self, length):
 		self.length = length
 		self.unionnumber=0
 		self.unionlist=[[]]
 		self.num=list(-1 for i in range(length))

 	def unite(self,i,j):
 		if self.num[i]==-1:
 			if self.num[j]==-1:
 				self.unionlist[self.unionnumber].extend([i,j])
 				self.num[i]=self.unionnumber
 				self.num[j]=self.unionnumber
 				self.unionnumber+=1
 				self.unionlist.append([])
 			else:
 				tmp=i 
 				i=j 
 				j=tmp 
 		if self.num[i]!=-1:
 			if self.num[j]!=-1:
 				if self.num[i]==self.num[j]:
 					pass
 				else:
 					self.unionlist[self.num[i]].extend(self.unionlist[self.num[j]])
 					tmp=self.num[j]
 					for k in self.unionlist[self.num[j]]:
 						self.num[k]=self.num[i]
 					self.unionlist[tmp]="del"
 			else:
 				self.num[j]=self.num[i]
 				self.unionlist[self.num[i]].append(j)

 	def same(self,i,j):
 		if self.num[i]==-1 or self.num[j]==-1:
 			return(False)
 		else:
 			return(self.num[i]==self.num[j])


N,K,L=list(map(int,input().split()))
road=union_find(N)
rail=union_find(N)

for i in range(K):
	a=list(map(int,input().split()))
	road.unite(a[0]-1,a[1]-1)

for i in range(L):
	a=list(map(int,input().split()))
	rail.unite(a[0]-1,a[1]-1)

res=[0 for i in range(N)]
for i in range(N):
	if res[i]==0:
		n=road.num[i]
		A=road.unionlist[n]
		m=rail.num[i]
		B=set(rail.unionlist[m]).intersection(A)
		l=len(B)
		if l==0:
			B=[i]
			l=1
		for j in B:
			res[j]=l

for i in res:
	print(i,end=" ")
print("")
















Fixed submission:
# マージO(n)かかっちゃう
class union_find:
	def __init__(self, size):
		# 負の値はルート (集合の代表) で集合の個数
		# 正の値は次の要素を表す
		self.size=size
		self.table = [-1 for _ in range(size)]
		self.num=[0 for i in range(size)]

	# 集合の代表を求める
	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			# 経路の圧縮
			self.table[x] = self.find(self.table[x])
			return(self.table[x])

	# 併合
	def unite(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] <= self.table[s2]:
				# 小さいほうが個数が多い
				self.table[s1] += self.table[s2]
				self.table[s2] = s1
			else:
				self.table[s2] += self.table[s1]
				self.table[s1] = s2
			return(True)
		return(False)

	def definite(self):
		for i in range(self.size):
			self.num[i]=self.find(i)
		return(True)


N,K,L=list(map(int,input().split()))
road=union_find(N)
rail=union_find(N)

for i in range(K):
	a=list(map(int,input().split()))
	road.unite(a[0]-1,a[1]-1)

for i in range(L):
	a=list(map(int,input().split()))
	rail.unite(a[0]-1,a[1]-1)

road.definite()
rail.definite()

dic={}
# print(road.num,rail.num)

for i in range(N):
	key=str(road.num[i])+":"+str(rail.num[i])
	if key in dic:
		dic[key].append(i)
	else:
		dic[key]=[i]

# print(dic)
res=[0 for i in range(N)]
for i in dic.values():
	l=len(i)
	for j in i:
		res[j]=l

for i in res:
	print(i,end=" ")
print("")