# |
Author |
Problem |
Lang |
Verdict |
Time |
Memory |
Sent |
Judged |
|
139919656 |
Practice:
agarus |
1620E
- 9
|
PyPy 3
|
Accepted
|
1076 ms
|
80268 KB
|
2021-12-19 21:06:09 |
2021-12-19 21:06:09 |
|
import sys
import io,os
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
IN = sys.stdin
OUT = sys.stdout
tc = int(IN.readline())
p = [None] * 500010
n = 0
n2 = 0
for ti in range(tc):
q = tuple(map(int, IN.readline().strip().split()))
q1 = q[1]
if q[0] == 1:
if p[q1]:
p[q1] = [ p[q1][0], n, p[q1] ]
else:
p[q1] = [ None, n, None ]
p[q1][0] = p[q1]
n += 1;
else:
q2 = q[2]
if q1 != q2:
if (p[q1]):
if p[q2]:
#p[q2].extend(p[q1])
p[q2][0][2] = p[q1]
p[q2][0] = p[q1][0]
else:
p[q2] = p[q1]
p[q1] = None
#n2 += 1
#if n2 > 300000:
# exit(1)
ans = [None] * n
for i in range(len(p)):
while p[i]:
ans[p[i][1]] = str(i)
p[i] = p[i][2]
#print(*ans)
#ans = ans[0:n]
sys.stdout.write(' '.join(ans))
#for a in ans:
# sys.stdout.write(str(a) + ' ')
# print(a, end=' ')
Click to see test details