first commit

from old repository to a new repository
This commit is contained in:
Gyubin Han
2024-04-30 16:59:10 +09:00
commit 2600340c03
93 changed files with 1610 additions and 0 deletions

29
boj/2606.py Normal file
View File

@@ -0,0 +1,29 @@
from sys import stdin
n=int(stdin.readline().rstrip())
m=int(stdin.readline().rstrip())
arr=[[0]*n for _ in range(n)]
for _ in range(m):
a,b=map(int,stdin.readline().rstrip().split())
a-=1
b-=1
arr[a][b]=arr[b][a]=1
visit=[0 for _ in range(n)]
visit[0]=1
next=[]
i=0
cnt=0
while True:
for j in range(n):
if visit[j]==0 and arr[i][j]==1:
cnt+=1
visit[j]=1
next.append(j)
if len(next)==0:
break
else:
i=next.pop()
print(cnt)