Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from collections import defaultdict
N,K,L=map(int, raw_input().split())

nl=[ [] for i in range(N+1) ]

c1=set()

for i in range(K):
	p,q=map(int, raw_input().split())
	nl[p].append(q)
	nl[q].append(p)
	c1.add(p)
	c1.add(q)

nl2=[ [] for i in range(N+1) ]
c2=set()

for i in range(L):
	p,q=map(int, raw_input().split())
	nl2[p].append(q)
	nl2[q].append(p)
	c2.add(p)
	c2.add(q)


road=[ None for i in range(N+1) ]
railway=[ None for i in range(N+1) ]
l1=defaultdict(lambda: [])
l2=defaultdict(lambda: [])

def bfs(start,nl,type):
	V=[ None for i in range(N+1)]
	q = deque([]) 
	V[start]=1
	tmp=[]
	tmp.append(start)

	if type=="road": road[start]=start
	elif type=="railway": railway[start]=start

	q.append(start)

	while len(q)!=0:
		v=q.popleft()
		for i in nl[v]:
			if V[i] is None:
				V[i]=1
				q.append(i)
				tmp.append(i)
				if type=="road": road[i]=start
				elif type=="railway": railway[i]=start

	if type=="road": l1[start]=tmp
	elif type=="railway": l2[start]=tmp				
	return V




for i in c1:
	if road[i] is None: bfs(i,nl,"road")


for i in c2:
	if railway[i] is None: bfs(i,nl2,"railway")



for idx,i in enumerate( zip(road,railway) ):
	x=i[0]; y=i[1]
	if idx==0: continue
	if (x and y) is None:
		print 1,
	else:
		print len( set(l1[x]) & set(l2[y]) ),
	
	



Fixed submission:
from collections import deque
from collections import Counter

N,K,L=map(int, raw_input().split())

nl=[ [] for i in range(N+1) ]

for i in range(K):
	p,q=map(int, raw_input().split())
	nl[p].append(q)
	nl[q].append(p)

nl2=[ [] for i in range(N+1) ]

for i in range(L):
	p,q=map(int, raw_input().split())
	nl2[p].append(q)
	nl2[q].append(p)


v1=[ None for i in range(N+1) ]
v2=[ None for i in range(N+1) ]


def bfs(start,nl,V,l):
	q = deque([]) 
	V[start]=1
	l[start]=start
	q.append(start)

	while len(q)!=0:
		v=q.popleft()
		for i in nl[v]:
			if V[i] is None:
				V[i]=1
				q.append(i)
				l[i]=start
			
	return V

l1=[ "" for i in range(N+1) ]
l2=[ "" for i in range(N+1) ]


for i in range(1,N+1):
	if v1[i] is None:
		bfs(i,nl,v1,l1)

for i in range(1,N+1):
	if v2[i] is None:
		bfs(i,nl2,v2,l2)


c=[]
for idx,i in enumerate( zip(l1,l2) ):
	x=i[0]; y=i[1]
	if idx==0: continue
	c.append( (x,y) )


C=Counter(c)

for idx,i in enumerate( zip(l1,l2) ):
	x=i[0]; y=i[1]
	if idx==0: continue
	print C[(x,y)],

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from collections import defaultdict
N,K,L=map(int, raw_input().split())

nl=[ [] for i in range(N+1) ]

c1=set()

for i in range(K):
	p,q=map(int, raw_input().split())
	nl[p].append(q)
	nl[q].append(p)
	c1.add(p)
	c1.add(q)

nl2=[ [] for i in range(N+1) ]
c2=set()

for i in range(L):
	p,q=map(int, raw_input().split())
	nl2[p].append(q)
	nl2[q].append(p)
	c2.add(p)
	c2.add(q)


road=[ None for i in range(N+1) ]
railway=[ None for i in range(N+1) ]

def bfs(start,nl,type):
	V=[ None for i in range(N+1)]
	q = deque([]) 
	V[start]=1
	if type=="road": road[start]=start
	elif type=="railway": railway[start]=start

	q.append(start)

	while len(q)!=0:
		v=q.popleft()
		for i in nl[v]:
			if V[i] is None:
				V[i]=1
				q.append(i)
				if type=="road": road[i]=start
				elif type=="railway": railway[i]=start					
	return V




for i in c1:
	if road[i] is None: bfs(i,nl,"road")


for i in c2:
	if railway[i] is None: bfs(i,nl2,"railway")



l1=defaultdict(lambda: [])
for i in range(1,N+1):
	if road[i] is not None:
		l1[road[i]].append(i)


l2=defaultdict(lambda: [])
for i in range(1,N+1):
	if railway[i] is not None:
		l2[railway[i]].append(i)


for idx,i in enumerate( zip(road,railway) ):
	x=i[0]; y=i[1]
	if idx==0: continue
	if (x and y) is None:
		print 1,
	else:
		print len( set(l1[x]) & set(l2[y]) ),
	
	



Fixed submission:
from collections import deque
from collections import Counter

N,K,L=map(int, raw_input().split())

nl=[ [] for i in range(N+1) ]

for i in range(K):
	p,q=map(int, raw_input().split())
	nl[p].append(q)
	nl[q].append(p)

nl2=[ [] for i in range(N+1) ]

for i in range(L):
	p,q=map(int, raw_input().split())
	nl2[p].append(q)
	nl2[q].append(p)


v1=[ None for i in range(N+1) ]
v2=[ None for i in range(N+1) ]


def bfs(start,nl,V,l):
	q = deque([]) 
	V[start]=1
	l[start]=start
	q.append(start)

	while len(q)!=0:
		v=q.popleft()
		for i in nl[v]:
			if V[i] is None:
				V[i]=1
				q.append(i)
				l[i]=start
			
	return V

l1=[ "" for i in range(N+1) ]
l2=[ "" for i in range(N+1) ]


for i in range(1,N+1):
	if v1[i] is None:
		bfs(i,nl,v1,l1)

for i in range(1,N+1):
	if v2[i] is None:
		bfs(i,nl2,v2,l2)


c=[]
for idx,i in enumerate( zip(l1,l2) ):
	x=i[0]; y=i[1]
	if idx==0: continue
	c.append( (x,y) )


C=Counter(c)

for idx,i in enumerate( zip(l1,l2) ):
	x=i[0]; y=i[1]
	if idx==0: continue
	print C[(x,y)],