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 |
Tags
- nGrinder
- aws ์ฟ ํฐ
- docker
- Entity
- Codedeploy ์ค๋ฅ
- AWS Certified Solutions Architect - Associate
- ํ๋ก๊ทธ๋๋จธ์ค ์ปฌ๋ฌ๋ง๋ถ
- JPA
- ๋ค์ค ์ปจํ ์ด๋
- ํ๋ก๊ทธ๋๋จธ์ค
- ์ ํจ์ค ๋น๋ ์ค๋ฅ
- docker compose
- aws saa ํฉ๊ฒฉ
- private subnet ec2 ๋ก์ปฌ ์ ์
- ์๋ฐ
- redis ์กฐํ
- ์คํํ๋ ๋ฏธ์ค
- prod docker-compose
- s3 ์ด๋ฏธ์ง ์ ์ฅ
- ์ ํจ์ค ์ค์ผ์ค๋ฌ
- redis ํ ์คํธ์ฝ๋
- Kafka
- docker-compose kafka
- s3 log ์ ์ฅ
- jvm ๋ฐ๋ฐ๋ฅ๊น์ง ํํค์น๊ธฐ
- s3 ์ด๋ฏธ์ง ๋ค์ด๋ก๋
- docker ps -a
- ํ์ดํผ๋ฐ์ด์
- ํ๋ก๊ทธ๋๋จธ์ค ํฉ์นํ์์๊ธ
- ์๋ฒ ํฐ์ง๋ ๋์ปค ์ฌ์คํ
Archives
- Today
- Total
๐๐ข๐๐ โ๐๐๐ ๐๐๐ก๐๐ ๐๐๐๐โง
[Python] ๋ฐฑ์ค 2606 & ๋ฐฑ์ค 1201 ๋ณธ๋ฌธ
๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ด๐ป/[๐๐ฒ๐ญ๐ก๐จ๐ง] ๐๐ฅ๐ ๐จ๐ซ๐ข๐ญ๐ก๐ฆ
[Python] ๋ฐฑ์ค 2606 & ๋ฐฑ์ค 1201
๐คRyusun๐ค 2023. 5. 28. 23:07# ๋ฐฑ์ค 2606 ๋ฐ์ด๋ฌ์ค
from collections import deque
n = int(input())
m = int(input())
graph = [[] for _ in range(n+1)]
visited = [False] * (n+1)
for _ in range(m):
a, b = map(int, input().split(' '))
graph[a].append(b)
graph[b].append(a)
def bfs(graph, start_node):
queue= deque()
queue.append(start_node)
visited[start_node] = True
while queue:
current_node = queue.popleft()
for next_node in graph[current_node]:
if visited[next_node]:
continue
visited[next_node] = True
queue.append(next_node)
return visited
bfs(graph, 1)
print(sum(visited)-1)
# ๋ฐฑ์ค 1201
from collections import deque
# ์ค๋ฅธ์ชฝ ์์ชฝ ์ผ์ชฝ ์๋์ชฝ
d_row = [0, -1, 0, +1]
d_col = [+1, 0, -1, 0]
def bfs(graph, visited, start_node):
queue = deque()
queue.append(start_node)
visited[start_node[0]][start_node[1]] = True
while queue:
current_node = queue.popleft()
for i in range(len(d_row)):
next_row = current_node[0] + d_row[i]
next_col = current_node[1] + d_col[i]
if next_row < 0 or next_col < 0 or next_row > n-1 or next_col > m-1:
continue
if visited[next_row][next_col] == True:
continue
if graph[next_row][next_col] == 0:
continue
next_node = [next_row, next_col]
queue.append(next_node)
visited[next_row][next_col] = True
graph[next_row][next_col] = 0
t = int(input())
for _ in range(t):
count = 0
n, m, k = map(int, input().split(' '))
graph = [[0] * m for _ in range(n)]
visited = [[False] * m for _ in range(n)]
for _ in range(k):
a, b = map(int, input().split(' '))
graph[a][b] = 1
for i in range(n):
for j in range(m):
if graph[i][j] == 1:
bfs(graph, visited, [i, j])
count += 1
print(count)
๐ Points
- graph[a].append(b), graph[b].append(a): ์๋ก ์์ด๋ฉด ์ฐ๊ฒฐ๋ ๋ ธ๋๋ฅผ ๊ฐ ๋ ธ๋์ ์ ์ฅํด์ผํ๋ค.
- visited ํ์ฉํ๊ธฐ
'๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ด๐ป > [๐๐ฒ๐ญ๐ก๐จ๐ง] ๐๐ฅ๐ ๐จ๐ซ๐ข๐ญ๐ก๐ฆ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python] ๋ฐฑ์ค 7576 & ๋ฐฑ์ค 14502 (0) | 2023.06.02 |
---|---|
[Python] ๋ฐฑ์ค 2206 & ๋ฐฑ์ค 1697 (0) | 2023.06.01 |
[Python] ๋ฐฑ์ค 1201 & ๋ฐฑ์ค 1158 (0) | 2023.05.27 |
[Python] ๋ฐํฌ(deque) (0) | 2023.04.22 |
[ํ๋ก๊ทธ๋๋จธ์ค] 42626๋ฒ ๋ ๋งต๊ฒ (0) | 2022.11.16 |