結果

問題 No.2319 Friends+
ユーザー amentorimaru
提出日時 2023-03-18 02:23:11
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,579 ms / 3,000 ms
コード長 855 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 91,392 KB
最終ジャッジ日時 2024-09-18 13:00:46
合計ジャッジ時間 57,923 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
input = sys.stdin.readline
#sys.setrecursionlimit(10000000)
def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for _ in range(N)]
            
def main():
    N,M=read_values()
    P=read_list()    
    pb=[0]*N
    for i in range(N):
        P[i]-=1
        pb[P[i]]^=1<<i
    fb=[0]*N
    for i in range(M):
        A,B=read_index()
        fb[A]^=1<<B
        fb[B]^=1<<A

    Q = int(input())
    for _ in range(Q):
        X,Y=read_index()
        if P[X]==P[Y] or (fb[X]&pb[P[Y]]==0):
            print("No")            
        else:
            print("Yes")
            pb[P[X]]^=1<<X
            pb[P[Y]]^=1<<X
            P[X]=P[Y]

if __name__ == "__main__":
    main()
0