結果

問題 No.3390 Public or Private
コンテスト
ユーザー detteiuu
提出日時 2025-11-28 21:46:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 518 ms / 2,000 ms
コード長 808 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 82,596 KB
実行使用メモリ 164,020 KB
最終ジャッジ日時 2025-11-28 21:47:15
合計ジャッジ時間 13,659 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict

N, M = map(int, input().split())
edge = [list(map(int, input().split())) for _ in range(M)]
Q = int(input())
query = [list(map(int, input().split())) for _ in range(Q)]

G = defaultdict(set)
for u, v in edge:
    u, v = u-1, v-1
    if v in G[u]:
        G[u].remove(v)
    else:
        G[u].add(v)

S = set()
for i in range(Q):
    q = query[i][0]
    if q == 1:
        a, b = query[i][1:]
        a, b = a-1, b-1
        if b in G[a]:
            G[a].remove(b)
        else:
            G[a].add(b)
    else:
        a = query[i][1]-1
        if a in S:
            S.remove(a)
        else:
            S.add(a)
    ans = N-1
    a = query[i][1]-1
    for s in S:
        if s == a:
            continue
        if s not in G[a]:
            ans -= 1
    print(ans)
0