Skip to content

Commit 6e77873

Browse files
authored
Merge pull request #45 from YoonYn9915/main
YoonYn9915 / 7월 3주차 / 2문제
2 parents d461a90 + a820733 commit 6e77873

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from collections import deque
2+
import sys
3+
4+
f = sys.stdin.readline
5+
6+
def bfs(visited, graph,k,x):
7+
visited[x] = 0
8+
queue = deque([x])
9+
answer = []
10+
11+
while queue:
12+
current_city = queue.popleft()
13+
for next_city in graph[current_city]:
14+
if visited[next_city] == -1:
15+
queue.append(next_city)
16+
visited[next_city] = visited[current_city] + 1
17+
if visited[next_city] == k:
18+
answer.append(next_city)
19+
20+
if not answer:
21+
print(-1)
22+
else:
23+
answer.sort()
24+
for ans in answer:
25+
print(ans)
26+
27+
28+
n,m,k,x = map(int, f().split())
29+
30+
graph = [[] for _ in range(n+1)]
31+
32+
33+
for i in range(m):
34+
a,b = map(int, f().split())
35+
graph[a].append(b)
36+
37+
visited = [-1] * (n+1)
38+
39+
bfs(visited, graph,k,x)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
n,m = map(int,input().split())
3+
4+
arr = list(map(int,input().split()))
5+
6+
arr.sort(reverse=True)
7+
num = 3
8+
9+
result = m
10+
answer = 0
11+
12+
for i in range(n):
13+
for j in range(i+1,n):
14+
for k in range(j+1,n):
15+
if arr[i]+arr[j]+arr[k] <= m:
16+
answer = max(answer,arr[i]+arr[j]+arr[k])
17+
break
18+
19+
print(answer)

0 commit comments

Comments
 (0)