Skip to content

Commit 332b2df

Browse files
Merge pull request #590 from gmlrude/main
[박희경] 82차 라이브 코테 제출
2 parents 53d1b42 + ef43abf commit 332b2df

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

live8/test82/문제1/박희경.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import sys
2+
from collections import *
3+
4+
input = sys.stdin.readline
5+
6+
n, m = map(int,input().split())
7+
8+
picture = []
9+
for _ in range(n):
10+
picture.append(list(map(int,input().split())))
11+
12+
13+
dx = [-1, 1, 0, 0]
14+
dy = [0, 0, -1, 1]
15+
visited = [[0] * m for _ in range(n)]
16+
17+
18+
def bfs(x, y):
19+
q = deque([(x, y)])
20+
size = 1
21+
visited[x][y] = 1
22+
while q:
23+
x, y = q.popleft()
24+
for i in range(4):
25+
nx, ny = x + dx[i], y + dy[i]
26+
if 0 <= nx < n and 0 <= ny < m and not visited[nx][ny]:
27+
if picture[nx][ny] == 1:
28+
size += 1
29+
visited[nx][ny] = 1
30+
q.append((nx, ny))
31+
return size
32+
33+
34+
cnt = 0
35+
max_extent = 0
36+
for i in range(n):
37+
for j in range(m):
38+
if picture[i][j] == 1 and not visited[i][j]:
39+
max_extent = max(bfs(i, j), max_extent)
40+
cnt += 1
41+
print(cnt)
42+
print(max_extent)
43+
44+
"""
45+
6 5
46+
1 1 0 1 1
47+
0 1 1 0 0
48+
0 0 0 0 0
49+
1 0 1 1 1
50+
0 0 1 1 1
51+
0 0 1 1 1
52+
"""

live8/test82/문제2/박희경.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import sys
2+
from collections import *
3+
4+
input = sys.stdin.readline
5+
6+
n, m = map(int, input().split())
7+
r = [[] for _ in range(n + 1)]
8+
for _ in range(m):
9+
a, b = map(int, input().split())
10+
r[a].append(b)
11+
r[b].append(a)
12+
13+
14+
def bfs(x, target, depth):
15+
visited = [0] * (n + 1)
16+
q = deque([(x, depth)])
17+
visited[x] = 1
18+
while q:
19+
x, depth = q.popleft()
20+
if x == target:
21+
return depth
22+
for nx in r[x]:
23+
if not visited[nx]:
24+
visited[nx] = 1
25+
q.append((nx, depth + 1))
26+
27+
28+
kb = [float("inf")] + []
29+
for i in range(1, n + 1):
30+
i_kb = 0
31+
for j in range(1, n + 1):
32+
if i != j:
33+
i_kb += bfs(i, j, 0)
34+
kb.append(i_kb)
35+
print(kb.index(min(kb)))
36+
37+
"""
38+
5 5
39+
1 3
40+
1 4
41+
4 5
42+
4 3
43+
3 2
44+
"""

0 commit comments

Comments
 (0)