結果

問題 No.2319 Friends+
ユーザー ShirotsumeShirotsume
提出日時 2023-05-26 22:42:56
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,112 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 105,988 KB
最終ジャッジ日時 2023-08-26 12:52:37
合計ジャッジ時間 11,776 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
76,056 KB
testcase_01 AC 81 ms
71,812 KB
testcase_02 AC 331 ms
103,496 KB
testcase_03 AC 345 ms
103,256 KB
testcase_04 AC 338 ms
103,628 KB
testcase_05 AC 322 ms
103,092 KB
testcase_06 AC 324 ms
102,552 KB
testcase_07 AC 425 ms
105,832 KB
testcase_08 AC 417 ms
105,920 KB
testcase_09 AC 418 ms
105,784 KB
testcase_10 AC 430 ms
105,824 KB
testcase_11 AC 419 ms
105,988 KB
testcase_12 AC 89 ms
72,324 KB
testcase_13 AC 91 ms
72,612 KB
testcase_14 AC 90 ms
72,624 KB
testcase_15 AC 89 ms
72,480 KB
testcase_16 AC 88 ms
72,716 KB
testcase_17 AC 79 ms
71,716 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque, Counter
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353

n, m = mi()

nowworld = [v - 1 for v in li()] #n人の今いるワールド

worldlist = [set() for _ in range(n)]

for i in range(n):
    worldlist[nowworld[i]].add(i)
graph = [set() for _ in range(n)]

for _ in range(m):
    u, v = mi()
    u -= 1; v -= 1
    graph[u].add(v)
    graph[v].add(u)

def common(x, y):
    if len(graph[x]) < len(worldlist[nowworld[y]]):
        for v in graph[x]:
            if v in worldlist[nowworld[y]]:
                return True
        return False
    else:
        for v in worldlist[nowworld[y]]:
            if v in graph[x]:
                return True
        return False
for _ in range(ii()):
    x, y = mi()
    x -= 1; y -= 1
    if nowworld[x] != nowworld[y] and common(x, y):
        worldlist[nowworld[x]].discard(x)
        nowworld[x] = nowworld[y]
        worldlist[nowworld[x]].add(x)
        print('Yes')
    else:
        print('No')
0