일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- ubuntu
- CSS
- MongoDB
- baekjun
- nav-tab
- Algorythm
- 트리
- algotythm
- 백준
- 라즈베리파이3
- 라즈비안
- bootstrap
- 13237
- Crawling
- springboot3.x
- 2909
- dp
- Python
- 16.04
- 파이썬
- 라즈베리파이3b+
- 라즈베리파이
- HTML
- 크롤링
- 2579
- NAV
- dynaminprogramming
- raspberrypi
- node.js
- 알고리즘
Archives
- Today
- Total
노트
[백준] 11724번 연결 요소의 개수 python 본문
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
# dfs 함수
def dfs(graph, v, visited):
visited[v] = True
for i in graph[v]:
if not visited[i]:
dfs(graph, i, visited)
n, m = map(int, input().split())
graph = [[] for _ in range(n+1)]
for i in range(m):
u, v = map(int, input().split())
graph[u].append(v)
graph[v].append(u)
count = 0
visited = [False] * (n+1)
for i in range(1, n+1):
if not visited[i]:
dfs(graph, i, visited)
count += 1
print(count)
'알고리즘' 카테고리의 다른 글
[백준] 1389번 케빈 베이컨의 6단계 법칙 python (0) | 2024.02.19 |
---|---|
[백준] 1010번 다리 놓기 python (1) | 2024.02.12 |
[백준] 2909번 캔디 구매 python (0) | 2024.01.28 |
[백준] 7785번 회사에 있는 사람 python (0) | 2024.01.11 |
[백준] 1417번 국회의원 선거 python (0) | 2023.12.09 |
Comments