結果

問題 No.416 旅行会社
ユーザー chocoruskchocorusk
提出日時 2020-09-26 17:47:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 484 ms / 4,000 ms
コード長 1,058 bytes
コンパイル時間 1,026 ms
コンパイル使用メモリ 86,912 KB
実行使用メモリ 215,724 KB
最終ジャッジ日時 2023-08-21 10:35:59
合計ジャッジ時間 7,802 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 231 ms
151,700 KB
testcase_01 AC 71 ms
71,080 KB
testcase_02 AC 71 ms
71,168 KB
testcase_03 AC 71 ms
71,076 KB
testcase_04 AC 70 ms
71,016 KB
testcase_05 AC 70 ms
71,136 KB
testcase_06 AC 72 ms
71,244 KB
testcase_07 AC 76 ms
75,296 KB
testcase_08 AC 95 ms
76,904 KB
testcase_09 AC 139 ms
84,376 KB
testcase_10 AC 234 ms
151,540 KB
testcase_11 AC 233 ms
153,028 KB
testcase_12 AC 237 ms
152,052 KB
testcase_13 AC 223 ms
151,772 KB
testcase_14 AC 428 ms
215,724 KB
testcase_15 AC 484 ms
215,640 KB
testcase_16 AC 434 ms
215,400 KB
testcase_17 AC 444 ms
215,616 KB
testcase_18 AC 425 ms
215,340 KB
testcase_19 AC 369 ms
167,664 KB
testcase_20 AC 370 ms
167,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

n, m, q=map(int, readline().split())
abcd=list(map(int ,read().split()))
a=abcd[:2*m:2]
b=abcd[1:2*m:2]
c=abcd[2*m::2]
d=abcd[2*m+1::2]
par=list(range(n))
v=[[i] for i in range(n)]
ans=[0]*n
def merge(x, y):
    if len(v[x])>len(v[y]):
        x, y=y, x
    while v[x]:
        z=v[x].pop()
        par[z]=y
        v[y].append(z)
cd=set(zip(c, d))
for x, y in zip(a, b):
    if (x, y) not in cd:
        x1, y1=par[x-1], par[y-1]
        if x1==y1:
            continue
        if x1==par[0]:
            for z in v[y1]:
                ans[z]=-1
        elif y1==par[0]:
            for z in v[x1]:
                ans[z]=-1
        merge(x1, y1)
for i in range(q-1, -1, -1):
    x, y=c[i]-1, d[i]-1
    x1, y1=par[x], par[y]
    if x1==y1:
        continue
    if x1==par[0]:
        for z in v[y1]:
            ans[z]=i+1
    elif y1==par[0]:
        for z in v[x1]:
            ans[z]=i+1
    merge(x1, y1)
print('\n'.join(map(str, ans[1:])))
0