-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
34-alstjr7437 #241
34-alstjr7437 #241
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from heapq import *
from collections import defaultdict
total_node_count, total_edge_count, target_node = map(int,input().split(" "))
visited = [False for _ in range(total_node_count+1)]
go_distance_table = [int(1e9) for _ in range(total_node_count+1)]
link_table = defaultdict(lambda: defaultdict(lambda : int(1e9)))
for _ in range(total_edge_count):
node1, node2, weight = map(int, input().split(" "))
link_table[node1][node2] = weight
#μ§μμ Xλ‘ κ°λ κΈΈ
for idx in range(1,total_node_count+1):
if idx == target_node:
go_distance_table[target_node] = 0
continue
heap = [[0,idx]]
temp_visited = [False for _ in range(total_node_count+1)]
temp_distance_table = [int(1e9) for _ in range(total_node_count+1)]
temp_distance_table[idx] = 0
while heap:
now_distance, now_node = heappop(heap)
temp_visited[now_node] = True
for link_node in link_table[now_node]:
if temp_visited[link_node] == True:
continue
if temp_distance_table[link_node] > now_distance + link_table[now_node][link_node] :
temp_distance_table[link_node] = now_distance + link_table[now_node][link_node]
heappush(heap,[temp_distance_table[link_node],link_node])
go_distance_table[idx] = temp_distance_table[target_node]
#Xμμ μ§μΌλ‘ λμκ°λ κΈΈ
come_distance_table = [int(1e9) for _ in range(total_node_count+1)]
heap = [[0,target_node]]
while heap:
now_distance, now_node = heappop(heap)
visited[now_node] = True
for link_node in link_table[now_node]:
if visited[link_node] == True:
continue
if come_distance_table[link_node] > now_distance + link_table[now_node][link_node] :
come_distance_table[link_node] = now_distance +link_table[now_node][link_node]
heappush(heap,[come_distance_table[link_node],link_node])
go_distance_table[target_node] = -1
come_distance_table[target_node] = -1
print(max([x+y for x,y in zip(go_distance_table[1:], come_distance_table[1:])]))
νν. μ΄λ κ² λ§μλ λ¬Έμ λ₯Ό λ΄μ£Όμ μ κ°μ¬ν©λλ€ ,,,, γ γ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ€μ΅μ€νΈλΌ n->x, x->n μ λ λ² λ리λκΉ λ°λ‘ λ΅ λμ€λ€μ©
λ€μ΅μ€νΈλΌ λ³΅μ΅ μ νμ΅λλ€μΉ ~! ~! ~π«‘
import sys
import heapq
INF = 1e8
def input() : return sys.stdin.readline().rstrip()
N, M, X = map(int, input().split())
T = [[] for _ in range(N+1)]
distance = [INF] * (N+1)
cmp = [0] * (N+1)
for _ in range(M):
u, v, w = map(int, input().split())
T[u].append((v, w))
def dijkstra(start):
q = []
heapq.heappush(q, (0, start))
distance[start] = 0
while q:
dist, now = heapq.heappop(q)
if distance[now] < dist:
continue
for i in T[now]:
if dist+i[1] < distance[i[0]]:
distance[i[0]] = dist+i[1]
heapq.heappush(q, (distance[i[0]], i[0]))
for i in range(N):
dijkstra(i+1)
cmp[i+1] = distance[X]
distance = [INF] * (N+1)
dijkstra(X)
for i in range(N):
cmp[i+1] += distance[i+1]
print(max(cmp))
π λ¬Έμ λ§ν¬
νν°
βοΈ μμλ μκ°
30λΆ
μ€λλ§μ λ€μ΅μ€νΈλΌ μ°μ΅κ²Έ κΈ°μ΅ λ³΅κ·λ₯Ό μν΄μ νμ΄λ΄€μ΅λλ€!!
κ·Έλ°λ° λ€νκ³ μ΄ν΄λ³΄λκΉ νκ·λμ λ¬Έμ μ μλκ΅°μ γ·γ·γ·...
λ¬Έμ μ
λ°λ‘ μ²μμλ λ¬Έμ κ° μ΄ν΄κ° κ°μ§ μμμ΅λλ€
λ§μ§λ§ κΈλ§ μ½κ³ λμμ κ°λλΌλ μ΅λλ‘ κ°λ λ°©λ²μ ꡬνμ!!
μΈμ€ μμλλ° κ²°κ³Όκ°μ 보λ 10μ΄ λμ€λλΌκ΅¬μ!!
μμΈν μ½μ΄λ³΄λ
μ΅λ¨ 거리
λ‘ κ°μ§λ§ κ·Έ μ€μ μ μΌ λ¨Ό μ λ₯Ό μΆλ ₯μ΄λλΌκ΅¬μβ¨ μλ μ½λ
μΌλ‘ ꡬνμ νμ΅λλ€!
μ½λ
π μλ‘κ² μκ²λ λ΄μ©