Skip to content

Commit ed50be6

Browse files
committed
2026년 04월 10일 05:46:40
1 parent 498aca8 commit ed50be6

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# [3258] Three Robots
2+
### 채점 결과
3+
Accepted
4+
### 제출 일자
5+
2026년 04월 10일 05:46:40
6+
### 성능 요약[추후 구현 예정]
7+
- 메모리: N/A KB
8+
- 시간: N/A ms
9+
---
10+
### 문제 링크
11+
https://code.pusan.ac.kr/problem/3258
12+
### 난이도
13+
어려움
14+
### 문제 설명
15+
An undirected weighted graph 𝐺 is given and 𝐺 is connected, that is, arbitrary two vertices in 𝐺 must be connected by a path. Three robots are exploring 𝐺 through edges. Here the weight of each edge means the time to be spent when a robot passes through it. The speeds of all the robots are identical and at least two robots may be passed through a same edge at a time. At some instant of the explorations of the robots, all of them should get together at a vertex to share their information. It is called a rendezvous.Initially, three robots lie on specified vertices. Of course, at least two robots may be located on an identical vertex. Also all the three robots start to move simultaneously. We wish to know the minimum time needed to fulfill the first rendezvous.For example, initially, three robots are located on the vertices 1, 5, and 7 in Figure L.1. A movement of the robot on the vertex 1 into the vertex 9 requires at least 9 time units. Also it takes at least 8 and 3 time units, respectively that the robots on the vertices 5 and 7 travel into the vertex 9. So the rendezvous at the vertex 9 requires at least 9 time units and it is the minimum time needed for the first rendezvous. Of course, the first rendezvous happens either at the vertex 1 or 4 and it also requires the minimum time of 9.Given a weighted and connected graph 𝐺 and the initial locations of three robots, write a program to find the minimum time needed to fulfill the first rendezvous.
16+
### 입력
17+
Your program is to read from standard input. The input starts with a line containing two integers, 𝑁 and 𝑀(1 ≤ 𝑁 ≤ 20,000, 𝑁 − 1 ≤ 𝑀 ≤ 100,000), where 𝑁 and 𝑀 are the numbers of vertices and edges of 𝐺, respectively. The vertices of 𝐺 are represented by 1, 2, … , 𝑁. In each of the following 𝑀 lines, three integers 𝑎, 𝑏, and 𝑡 (1 ≤ 𝑎 ≠ 𝑏 ≤ 𝑁, 1 ≤ 𝑡 ≤ 10,000) are given, where an edge connects the two vertices 𝑎 and 𝑏, and its weight is 𝑡. The last (𝑀 + 2)-th line contains three integers 𝑢, 𝑣, and 𝑤, which are the initial locations ofthree robots (1 ≤ 𝑢, 𝑣, 𝑤 ≤ 𝑁). Of course, it is possible that at least two of the three robots are initially located on an identical vertex.
18+
### 출력
19+
Your program is to write to standard output. Print exactly one line which contains the minimum time needed to fulfill the first rendezvous.
20+
### 예제 입력/출력
21+
**예제 입력 1**
22+
```
23+
4 6
24+
1 2 8
25+
3 2 6
26+
3 1 1
27+
1 4 10
28+
4 2 2
29+
3 4 3
30+
1 1 2
31+
```
32+
**예제 출력 1**
33+
```
34+
4
35+
```
36+
**예제 입력 2**
37+
```
38+
9 13
39+
1 2 5
40+
3 1 6
41+
1 4 1
42+
2 5 4
43+
3 4 3
44+
5 4 9
45+
6 3 2
46+
4 7 5
47+
8 5 6
48+
7 8 9
49+
5 9 8
50+
7 6 1
51+
7 9 3
52+
1 5 7
53+
```
54+
**예제 출력 2**
55+
```
56+
9
57+
```
58+
### 제약 사항
59+
- 시간 제한 1000ms
60+
- 메모리 제한 256mb
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import sys
2+
import heapq
3+
4+
def dijkstra(start):
5+
dist = [float('inf')] * (N+1)
6+
dist[start] = 0
7+
queue = [(0, start)]
8+
9+
while queue:
10+
curr_dist, curr_node = heapq.heappop(queue)
11+
12+
if dist[curr_node] < curr_dist:
13+
continue
14+
15+
for neighbor, weight in graph[curr_node]:
16+
distance = curr_dist + weight
17+
if distance < dist[neighbor]:
18+
dist[neighbor] = distance
19+
heapq.heappush(queue, (distance, neighbor))
20+
return dist
21+
22+
input = sys.stdin.readline
23+
24+
N, M = map(int, input().split())
25+
graph = [[] for _ in range(N+1)]
26+
27+
for _ in range(M):
28+
a, b, t = map(int, input().split())
29+
graph[a].append((b, t))
30+
graph[b].append((a, t))
31+
32+
u, v, w = map(int, input().split())
33+
34+
dist_u = dijkstra(u)
35+
dist_v = dijkstra(v)
36+
dist_w = dijkstra(w)
37+
38+
min_time = float('inf')
39+
40+
for i in range(1, N+1):
41+
max_time = max(dist_u[i], dist_v[i], dist_w[i])
42+
43+
if max_time < min_time:
44+
min_time = max_time
45+
46+
print(min_time)

0 commit comments

Comments
 (0)