Skip to content

Commit

Permalink
Merge pull request #24 from INIT-Algorithm/jiyoon
Browse files Browse the repository at this point in the history
#21 : Week5_지윤이티
  • Loading branch information
ziy00n authored May 23, 2023
2 parents 9fe60f1 + efb8cb1 commit cf1fb9a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 이티지윤/2606_바이러스BFS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys
from collections import deque

N = int(sys.stdin.readline())
C = int(sys.stdin.readline())

graph = [[] for i in range(N+1)]

for i in range(C):
a, b = map(int,sys.stdin.readline().split())
graph[a].append(b)
graph[b].append(a)

visited = []
def bfs(x):
q = deque([x])
visited.append(x)

while q:
v = q.popleft()
for i in graph[v]:
if i not in visited:
q.append(i)
visited.append(i)

bfs(1)
print(len(visited) -1) # 1번 컴퓨터는 제외
27 changes: 27 additions & 0 deletions 이티지윤/2606_바이러스DFS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys

n = int(sys.stdin.readline()) # 컴퓨터의 개수
m = int(sys.stdin.readline()) # 쌍의 개수

graph = [[] for _ in range(n + 1)]

for i in range(m):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)

result = 0
visited = [0] * (n + 1)


def dfs(start):
global result
visited[start] = 1
for j in graph[start]:
if visited[j] == 0:
result += 1
dfs(j)


dfs(1)
print(result)

0 comments on commit cf1fb9a

Please sign in to comment.