結果

問題 No.2319 Friends+
ユーザー titiatitia
提出日時 2023-10-05 00:44:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,149 ms / 3,000 ms
コード長 691 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 315,572 KB
最終ジャッジ日時 2023-10-05 00:45:38
合計ジャッジ時間 72,569 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,300 KB
testcase_01 AC 68 ms
71,396 KB
testcase_02 AC 347 ms
105,620 KB
testcase_03 AC 370 ms
105,596 KB
testcase_04 AC 338 ms
105,836 KB
testcase_05 AC 333 ms
105,816 KB
testcase_06 AC 336 ms
105,556 KB
testcase_07 AC 1,729 ms
314,848 KB
testcase_08 AC 1,708 ms
313,660 KB
testcase_09 AC 1,742 ms
313,544 KB
testcase_10 AC 1,735 ms
314,460 KB
testcase_11 AC 1,688 ms
313,616 KB
testcase_12 AC 74 ms
71,628 KB
testcase_13 AC 80 ms
71,544 KB
testcase_14 AC 74 ms
71,308 KB
testcase_15 AC 75 ms
71,356 KB
testcase_16 AC 73 ms
71,508 KB
testcase_17 AC 69 ms
71,156 KB
testcase_18 AC 1,371 ms
294,712 KB
testcase_19 AC 1,849 ms
311,776 KB
testcase_20 AC 1,693 ms
314,504 KB
testcase_21 AC 1,696 ms
314,108 KB
testcase_22 AC 1,714 ms
314,404 KB
testcase_23 AC 1,878 ms
315,572 KB
testcase_24 AC 1,910 ms
315,144 KB
testcase_25 AC 1,802 ms
314,304 KB
testcase_26 AC 1,792 ms
314,196 KB
testcase_27 AC 1,790 ms
314,084 KB
testcase_28 AC 1,767 ms
314,860 KB
testcase_29 AC 1,723 ms
314,456 KB
testcase_30 AC 1,708 ms
314,124 KB
testcase_31 AC 1,735 ms
314,396 KB
testcase_32 AC 1,748 ms
314,940 KB
testcase_33 AC 1,748 ms
314,280 KB
testcase_34 AC 1,817 ms
315,164 KB
testcase_35 AC 1,850 ms
314,300 KB
testcase_36 AC 1,282 ms
279,304 KB
testcase_37 AC 1,218 ms
174,664 KB
testcase_38 AC 2,097 ms
314,596 KB
testcase_39 AC 2,115 ms
314,256 KB
testcase_40 AC 2,138 ms
314,460 KB
testcase_41 AC 2,107 ms
314,180 KB
testcase_42 AC 2,115 ms
314,072 KB
testcase_43 AC 2,149 ms
314,084 KB
testcase_44 AC 2,025 ms
310,424 KB
testcase_45 AC 1,720 ms
293,240 KB
testcase_46 AC 1,439 ms
265,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
P=list(map(int,input().split()))

for i in range(N):
    P[i]-=1

Friends=[0]*N

for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    Friends[a]|=1<<b
    Friends[b]|=1<<a

Rooms=[0]*N

for i in range(N):
    x=P[i]
    Rooms[x]|=(1<<i)

Q=int(input())

for tests in range(Q):
    x,y=map(int,input().split())
    x-=1
    y-=1

    room=P[y]

    #print(P,Rooms,Friends)

    if P[x]==P[y] or Rooms[room] & Friends[x]==0:
        print("No")
        continue
    else:
        print("Yes")
        mae=P[x]
        Rooms[mae]^=1<<x

        P[x]=P[y]
        Rooms[P[x]]^=1<<x
        
        
    

0