Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit41b3b0a

Browse files
committed
최단경로 - 전보
1 parent265aa15 commit41b3b0a

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

‎9/5.py

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
INF=int(1e9)# 무한을 의미하는 값으로 10억을 설정
55

66
# 노드의 개수, 간선의 개수, 시작 노드를 입력받기
7-
n,m,start=map(int,input().split())
7+
# n, m, start = map(int, input().split())
8+
# n, m, start = 0;
89
# 각 노드에 연결되어 있는 노드에 대한 정보를 담는 리스트를 만들기
9-
graph= [[]foriinrange(n+1)]
10+
graph= []
1011
# 최단 거리 테이블을 모두 무한으로 초기화
11-
distance= [INF]* (n+1)
12+
distance= []
1213

1314
# 모든 간선 정보를 입력받기
14-
for_inrange(m):
15-
x,y,z=map(int,input().split())
16-
# X번 노드에서 Y번 노드로 가는 비용이 Z라는 의미
17-
graph[x].append((y,z))
15+
#for _ in range(m):
16+
# x, y, z = map(int, input().split())
17+
# # X번 노드에서 Y번 노드로 가는 비용이 Z라는 의미
18+
# graph[x].append((y, z))
19+
#x, y, z = 0
1820

1921
defdijkstra(start):
2022
q= []
@@ -35,17 +37,32 @@ def dijkstra(start):
3537
heapq.heappush(q, (cost,i[0]))
3638

3739
# 다익스트라 알고리즘을 수행
38-
dijkstra(start)
39-
40-
# 도달할 수 있는 노드의 개수
41-
count=0
42-
# 도달할 수 있는 노드 중에서, 가장 멀리 있는 노드와의 최단 거리
43-
max_distance=0
44-
fordindistance:
45-
# 도달할 수 있는 노드인 경우
46-
ifd!=1e9:
47-
count+=1
48-
max_distance=max(max_distance,d)
49-
50-
# 시작 노드는 제외해야 하므로 count - 1을 출력
51-
print(count-1,max_distance)
40+
41+
42+
43+
if__name__=="__main__":
44+
n=3
45+
m=2
46+
start=1
47+
graph= [[]foriinrange(n+1)]
48+
graph[1].append((2,4))
49+
graph[1].append((3,2))
50+
51+
# 최단 거리 테이블을 모두 무한으로 초기화
52+
distance= [INF]* (n+1)
53+
54+
dijkstra(start)
55+
56+
# 도달할 수 있는 노드의 개수
57+
count=0
58+
# 도달할 수 있는 노드 중에서, 가장 멀리 있는 노드와의 최단 거리
59+
max_distance=0
60+
fordindistance:
61+
# 도달할 수 있는 노드인 경우
62+
ifd!=1e9:
63+
count+=1
64+
max_distance=max(max_distance,d)
65+
66+
# 시작 노드는 제외해야 하므로 count - 1을 출력
67+
print(count-1,max_distance)
68+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp