結果

問題 No.3390 Public or Private
コンテスト
ユーザー urunea
提出日時 2025-12-02 02:12:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 441 ms / 2,000 ms
コード長 935 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 293 ms
コンパイル使用メモリ 82,224 KB
実行使用メモリ 154,208 KB
最終ジャッジ日時 2025-12-02 02:13:11
合計ジャッジ時間 11,906 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N, M = (int(x) for x in input().split())
offline = set()
d={}
for i in range(M):
    u, v = (int(x) for x in input().split())
    if u not in d:
        d[u] = set()
    d[u].add(v)

ans = []
Q=int(input())
for i in range(Q):
    q=list(map(int, input().split()))
    if q[0] == 1:
        a, b = q[1], q[2]
        if a not in d:
            d[a] = set()
            d[a].add(b)
        elif b not in d[a]:
            d[a].add(b)
        else:
            d[a].discard(b)
        res = 0
        for j in offline:
            if (a not in d or j not in d[a]) and a != j:
                res += 1
        ans.append(N-1-res)
    else:
        a = q[1]
        res = 0
        if a not in offline:
            offline.add(a)
        else:
            offline.discard(a)

        for j in offline:
            if (a not in d or j not in d[a]) and a != j:
                res += 1

        ans.append(N-1-res)

for i in ans:
    print(i)
0