Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 투포인터
- join
- 재귀
- 수학
- 서브쿼리
- 그래프 이론
- 에라토스테네스의 체
- DP
- 트리
- 다이나믹프로그래밍
- 자료구조
- 분할정복
- 시뮬레이션
- 다익스트라
- 다이나믹 프로그래밍
- DFS
- 누적합
- 플로이드-워셜
- 구현
- MST
- 우선순위큐
- 그리디
- 크루스칼
- GROUP BY
- 그래프 탐색
- 브루트포스
- 다시
- 해시
- 백트래킹
- BFS
Archives
- Today
- Total
기록하고 까먹지 말기
2606 본문
날짜 : 2022. 10. 19
사용 언어 : python
문제
코드
import sys
cnt = 0
def dfs(node):
global cnt
for i in pc[node]:
if not infested[i]: # 감염되지 않은 경우
infested[i] = True # 감염
cnt += 1 # 개수 증가
dfs(i) # 숙주
return
n = int(sys.stdin.readline())
c = int(sys.stdin.readline()) # 서로 연결된 컴퓨터 (conntected)
pc = [[]for i in range(n+1)]
infested = [False] * (n+1) # 감염여부 (infested)
for _ in range(c):
a, b = map(int, sys.stdin.readline().split())
pc[a].append(b)
pc[b].append(a)
for i in pc:
i.sort()
infested[1] = True
dfs(1)
print(cnt)
#print(infested)
알게된 점
- 어제 구름 챌린지에서 고배를 마시고 오늘 DFS문제를 풀었다.
- 기본적인 DFS문제였고 기본문제는 어느정도 감이 잡힌 듯(?) 보인다.
참고 사이트
-