Submission #43199990


Source Code Expand

Copy
from collections import defaultdict
N, Q = map(int, input().split())
edge = defaultdict(set)
ans = N
for _ in range(Q):
type, *args = map(int, input().split())
if type == 1:
u, v = args
for x in [u, v]:
if not edge[x]:
ans -= 1
edge[u].add(v)
edge[v].add(u)
print(ans)
else:
v = args[0]
for x in edge[v]:
edge[x].remove(v)
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
from collections import defaultdict

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

edge = defaultdict(set)
ans = N

for _ in range(Q):
  type, *args = map(int, input().split())
  if type == 1:
    u, v = args
    for x in [u, v]:
      if not edge[x]: 
        ans -= 1
    edge[u].add(v)
    edge[v].add(u)
    print(ans)
  else:
    v = args[0]
    for x in edge[v]:
      edge[x].remove(v)
      if not edge[x]:
        ans += 1
    if edge[v]:
      edge[v] = set()
      ans += 1
    print(ans)

Submission Info

Submission Time
Task E - Isolation
User arakaki_tokyo
Language Python (3.8.2)
Score 0
Code Size 513 Byte
Status TLE
Exec Time 2126 ms
Memory 113220 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 425
Status
AC × 2
AC × 34
TLE × 1
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt
Case Name Status Exec Time Memory
example_00.txt AC 30 ms 9040 KB
example_01.txt AC 21 ms 9036 KB
hand_00.txt TLE 2126 ms 113220 KB
hand_01.txt AC 1646 ms 61212 KB
hand_02.txt AC 1731 ms 60972 KB
hand_03.txt AC 1493 ms 9172 KB
hand_04.txt AC 1303 ms 9248 KB
hand_05.txt AC 1645 ms 56992 KB
hand_06.txt AC 1688 ms 60968 KB
hand_07.txt AC 1862 ms 60972 KB
random_00.txt AC 803 ms 9276 KB
random_01.txt AC 1393 ms 9312 KB
random_02.txt AC 335 ms 9248 KB
random_03.txt AC 895 ms 13268 KB
random_04.txt AC 1561 ms 9844 KB
random_05.txt AC 1090 ms 50040 KB
random_06.txt AC 1182 ms 37808 KB
random_07.txt AC 1577 ms 10572 KB
random_08.txt AC 1558 ms 47700 KB
random_09.txt AC 1523 ms 47648 KB
random_10.txt AC 677 ms 9948 KB
random_11.txt AC 962 ms 16060 KB
random_12.txt AC 715 ms 9384 KB
random_13.txt AC 684 ms 14000 KB
random_14.txt AC 1487 ms 32704 KB
random_15.txt AC 733 ms 11048 KB
random_16.txt AC 1142 ms 26500 KB
random_17.txt AC 1589 ms 35696 KB
random_18.txt AC 869 ms 16416 KB
random_19.txt AC 1402 ms 61160 KB
random_20.txt AC 1588 ms 40452 KB
random_21.txt AC 1054 ms 23300 KB
random_22.txt AC 1748 ms 66424 KB
random_23.txt AC 1786 ms 95308 KB
random_24.txt AC 1433 ms 85192 KB


2025-04-05 (Sat)
21:49:00 +00:00