from collections import deque
def dfs():
cnt=0
d=deque()
d.append(1)
while d:
cnt+=1
a=d.pop()
for i in t[a]:
d.append(i)
return cnt-1
for i in range(int(input())):
m,n=map(int,input().split())
t=dict()
for j in range(n):
a,b=map(int,input().split())
if a in t:
t[a].append(b)
else:t[a]=[b]
if b in t:
t[b].append(a)
else:t[b]=[a]
print(dfs())
'알고리즘 > 백준' 카테고리의 다른 글
백준-9498번(시험 성적)-python3 (0) | 2023.11.30 |
---|---|
백준-9461번(파도반 수열)-python3 (0) | 2023.11.30 |
백준-9184번(신나는 함수 실행)-python3 (0) | 2023.11.29 |
백준-9093번(단어 뒤집기)-python3 (0) | 2023.11.29 |
백준-9020번(골드바흐의 추측)-python3 (0) | 2023.11.29 |