結果

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

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

from collections import defaultdict

N,M=map(int,input().split())

SET=set()
D=defaultdict(set)

for i in range(M):
    x,y=map(int,input().split())

    D[y].add(x)

Q=int(input())

for tests in range(Q):
    q,a,b=map(int,input().split())

    if q==1:
        if a in D[b]:
            D[b].remove(a)
        else:
            D[b].add(a)
    else:
        if a in SET:
            SET.remove(a)
        else:
            SET.add(a)

    ANS=N-1

    for s in SET:
        if s==a:
            continue
        if a in D[s]:
            pass
        else:
            ANS-=1

    print(ANS)
0