結果
| 問題 |
No.2319 Friends+
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 21:44:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,277 bytes |
| コンパイル時間 | 297 ms |
| コンパイル使用メモリ | 82,120 KB |
| 実行使用メモリ | 142,948 KB |
| 最終ジャッジ日時 | 2025-04-15 21:45:52 |
| 合計ジャッジ時間 | 10,936 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 16 TLE * 1 -- * 28 |
ソースコード
import sys
from collections import defaultdict
def main():
input = sys.stdin.read().split()
ptr = 0
n, m = int(input[ptr]), int(input[ptr+1])
ptr += 2
p = list(map(int, input[ptr:ptr+n]))
ptr += n
current_world = [0] * (n + 1) # 1-based indexing
for i in range(n):
current_world[i+1] = p[i]
inhabitants = defaultdict(set)
for i in range(1, n+1):
inhabitants[current_world[i]].add(i)
friends = [set() for _ in range(n+1)]
for _ in range(m):
a = int(input[ptr])
b = int(input[ptr+1])
ptr += 2
friends[a].add(b)
friends[b].add(a)
q = int(input[ptr])
ptr += 1
for _ in range(q):
x = int(input[ptr])
y = int(input[ptr+1])
ptr += 2
x_w = current_world[x]
y_w = current_world[y]
if x_w == y_w:
print("No")
continue
# Check if friends[x] and inhabitants[y_w] have any common element
if not friends[x].isdisjoint(inhabitants[y_w]):
print("Yes")
# Move x from x_w to y_w
inhabitants[x_w].remove(x)
inhabitants[y_w].add(x)
current_world[x] = y_w
else:
print("No")
if __name__ == "__main__":
main()
lam6er