Skip to content

Commit a56773d

Browse files
Merge pull request #589 from gmlrude/main
[박희경] 81차 라이브 코테 제출
2 parents b69452c + 8060d49 commit a56773d

3 files changed

Lines changed: 115 additions & 0 deletions

File tree

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import sys
2+
from collections import *
3+
4+
input = sys.stdin.readline
5+
6+
n, m, v = map(int, input().split())
7+
graph = [[] * (n + 1) for _ in range(n + 1)]
8+
9+
visited1 = [0] * (n + 1)
10+
visited2 = [0] * (n + 1)
11+
12+
for _ in range(m):
13+
a, b = map(int, input().split())
14+
graph[a].append(b)
15+
graph[b].append(a)
16+
17+
for node in graph:
18+
node.sort()
19+
20+
def dfs(start):
21+
visited1[start] = 1
22+
print(start, end=' ')
23+
if len(graph[start]) != 0:
24+
for i in graph[start]:
25+
if not visited1[i]:
26+
dfs(i)
27+
28+
29+
def bfs(start):
30+
q = deque([start])
31+
while q:
32+
x = q.popleft()
33+
visited2[x] = 1
34+
print(x, end=' ')
35+
for i in graph[x]:
36+
if not visited2[i]:
37+
visited2[i] = 1
38+
q.append(i)
39+
40+
dfs(v)
41+
print()
42+
bfs(v)
43+
44+
"""
45+
4 5 1
46+
1 2
47+
1 3
48+
1 4
49+
2 4
50+
3 4
51+
---
52+
5 5 3
53+
5 4
54+
5 2
55+
1 2
56+
3 4
57+
3 1
58+
"""

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import sys
2+
from collections import *
3+
4+
input = sys.stdin.readline
5+
6+
n = int(input())
7+
m = int(input())
8+
network = [[] for _ in range(n + 1)]
9+
10+
for _ in range(m):
11+
x, y = map(int, input().split())
12+
network[x].append(y)
13+
network[y].append(x)
14+
15+
visited = [0] * (n + 1)
16+
q = deque([1])
17+
while q:
18+
x = q.popleft()
19+
visited[x] = 1
20+
for nx in network[x]:
21+
if not visited[nx]:
22+
visited[nx] = 1
23+
q.append(nx)
24+
25+
print(sum(visited) - 1)
26+
27+
"""
28+
7
29+
6
30+
1 2
31+
2 3
32+
1 5
33+
5 2
34+
5 6
35+
4 7
36+
"""

live8/test81/문제3/박희경.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from collections import *
2+
3+
4+
def solution(records):
5+
result = []
6+
answer = []
7+
user = defaultdict()
8+
for record in records:
9+
cmd = list(map(str, record.split()))
10+
if cmd[0] != 'Leave': # {유저 아이디: 닉네임}
11+
user[cmd[1]] = cmd[-1]
12+
if cmd[0] != 'Change':
13+
result.append([cmd[0], cmd[1]])
14+
15+
for res in result:
16+
if res[0] == 'Enter':
17+
answer.append(user[res[1]] + "님이 들어왔습니다.")
18+
if res[0] == 'Leave':
19+
answer.append(user[res[1]] + "님이 나갔습니다.")
20+
21+
return answer

0 commit comments

Comments
 (0)