結果

問題 No.2319 Friends+
ユーザー navel_tosnavel_tos
提出日時 2023-05-26 22:51:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,951 ms / 3,000 ms
コード長 2,531 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 87,316 KB
実行使用メモリ 209,916 KB
最終ジャッジ日時 2023-08-26 13:09:20
合計ジャッジ時間 38,533 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,724 KB
testcase_01 AC 80 ms
71,784 KB
testcase_02 AC 1,130 ms
206,332 KB
testcase_03 AC 1,195 ms
208,044 KB
testcase_04 AC 1,141 ms
208,292 KB
testcase_05 AC 1,203 ms
209,916 KB
testcase_06 AC 1,168 ms
209,520 KB
testcase_07 AC 758 ms
90,792 KB
testcase_08 AC 779 ms
91,052 KB
testcase_09 AC 760 ms
90,900 KB
testcase_10 AC 806 ms
91,248 KB
testcase_11 AC 781 ms
90,956 KB
testcase_12 AC 108 ms
77,292 KB
testcase_13 AC 108 ms
77,180 KB
testcase_14 AC 110 ms
77,444 KB
testcase_15 AC 116 ms
78,380 KB
testcase_16 AC 107 ms
77,308 KB
testcase_17 AC 83 ms
71,636 KB
testcase_18 AC 721 ms
96,804 KB
testcase_19 AC 694 ms
95,964 KB
testcase_20 AC 709 ms
91,996 KB
testcase_21 AC 716 ms
91,840 KB
testcase_22 AC 722 ms
91,312 KB
testcase_23 AC 706 ms
93,724 KB
testcase_24 AC 716 ms
93,012 KB
testcase_25 AC 703 ms
92,644 KB
testcase_26 AC 687 ms
93,052 KB
testcase_27 AC 694 ms
92,692 KB
testcase_28 AC 692 ms
92,440 KB
testcase_29 AC 748 ms
91,076 KB
testcase_30 AC 693 ms
91,308 KB
testcase_31 AC 681 ms
92,000 KB
testcase_32 AC 677 ms
91,020 KB
testcase_33 AC 667 ms
91,904 KB
testcase_34 AC 741 ms
92,312 KB
testcase_35 AC 708 ms
92,380 KB
testcase_36 AC 672 ms
86,468 KB
testcase_37 AC 1,654 ms
140,392 KB
testcase_38 AC 710 ms
92,324 KB
testcase_39 AC 694 ms
92,164 KB
testcase_40 AC 683 ms
92,092 KB
testcase_41 AC 695 ms
91,824 KB
testcase_42 AC 678 ms
91,064 KB
testcase_43 AC 695 ms
91,020 KB
testcase_44 AC 695 ms
90,400 KB
testcase_45 AC 1,951 ms
134,904 KB
testcase_46 AC 777 ms
135,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yukicoder390F Friends+

'''
フレンド関係があり、joinコマンドで移動する。
異なるワールドにいて、かつ、移動先にフレンドが一人いるときだけ移動可能。
コマンドの成否を判定しろ。

いまどこ?と友達?を判定しよう。
友達関係はUFを使えばいいか。
友達が特定の場所にいるか?の判定が面倒だな。

これタスク分割ですかね?
友達が多い人は、「いまぼくここだよ」で処理。
友達が少ない人は逐次確認。

カットオフはどれくらいだろう。300人くらい?
前は「ウニグラフで630人くらいがカットオフ」って話があったな。
今回はNが小さくて済むから、200人くらいにしておこうかな。

要件確認。
非vip: 全友達の現在地を逐次確認する。移動先にいれば移動する。
       移動後、現在地をvipに送付する。
vip: 非vipの友達の現在地は即座に確認する。
     vipの友達の現在地は逐次確認する。

提出デバッグの可能性が高そう。vipの閾値は手動変更できるようにしておこう。

まじかよ、MLEした。ショック。
N*N の配列を持つだけで死ぬので、ちょっと工夫するか・・・
'''

from collections import defaultdict as dd
f=lambda:list(map(int,input().split()))

N,M=f(); P=list(map(lambda x: x-1,f())); G=[[] for _ in range(N)]
for _ in range(M): a,b=f(); G[a-1].append(b-1); G[b-1].append(a-1)

vip_cutoff=300  #カットオフを入力してください
vip=set()
for i in range(N):
    if len(G[i])>=vip_cutoff: vip.add(i)

#vip用の、非vipの者どもの所在確認リストを用意する
V=dd(lambda:[0]*N); Comeon=[set() for _ in range(N)]
for vipper in vip:
    for next in G[vipper]:
        Comeon[next].add(vipper)
        if next not in vip: V[vipper][P[next]]+=1  #非vipの人の居場所だけを格納する

for _ in range(int(input())):
    x,y=f(); x-=1; y-=1; before=P[x]
    if P[x]==P[y]: print('No'); continue
    if x not in vip:
        for next in G[x]:
            if P[next]==P[y]:
                P[x]=P[y]; print('Yes')
                for vipper in Comeon[x]:
                    V[vipper][before]-=1; V[vipper][P[x]]+=1
                break
        else: print('No')
    else:
        if V[x][P[y]]==0:
            for next in Comeon[x]:
                if P[next]==P[y]: P[x]=P[y]; print('Yes'); break
            else: print('No')
        else: P[x]=P[y]; print('Yes')
0