-
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
80-tgyuuAn #254
80-tgyuuAn #254
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.
- list μΆλ ₯ ν¬λ§·μ μ© μν΄μ
- λ€μ΅μ€νΈλΌμμ μ΄κΈ°νκ° μλͺ»λΌμ
μ€λλ μ§κ² ν
μΌλ₯Ό ν΅ν΄ νμμ΅λλ€ νν«
1μκ° 10λΆ μ« λκ² νμμ΅λλ₯ ...!>!!>!>!>!>!>
PRμμ λ§μνμ λλ‘ κ²½λ‘μΆλ ₯νλκ² λ―μ€κΈ΄ νλλ° μ¬μ°¨μ μ°¨ν΄μ ν΄κ²°νμ΅λλ€!!
#85 보λκΉ μ΄μ κ²½λ‘λ§μ μ μ₯ν΄μ μμΆμ .. νλ λ°©λ²μ΄ μμκ΅°μ ....
μ λ λ
λ€ λ°°μ΄μ λ€ μ μ₯νκ³ , μ λ
Έλ κ²½λ‘λ₯Ό μΆκ°νμ¬ κ°±μ νλ μμΌλ‘ μ§ννμ΅λλ€
νμ μ¬μ©νμΌλ©΄ κ²½λ‘ μΆμ λ κ·Έλ κ³ λ€μ΅μ€νΈλΌλ μ’λ κ°λ¨νκ² ν μ μμκ² λ€μ© ..
# 9μ 20λΆ μμ
import sys
def input() : return sys.stdin.readline().rstrip()
n = int(input()) # 1000
m = int(input()) # 100000
info = [ [] for _ in range(n+1)]
# λμλ²νΈ(μΆλ°μ§) λμλ²νΈ(λμ°©μ§) λ²μ€λΉμ©
for i in range(m):
s, e, c = map(int, input().split())
info[s].append((e,c))
start_city, end_city = map(int, input().split())
cost = [1e9 for _ in range(n+1)]
path = [[] for _ in range(n+1)]
visited = [False for _ in range(n+1)]
def get_min_cost_node():
min_cost = 1e9
idx = 0
for i in range(1,n+1):
if cost[i] < min_cost and not visited[i]:
min_cost = cost[i]
idx = i
return idx
# λ€μ΅μ€νΈλΌμ
def Dijikstra(start):
cost[start] = 0
visited[start] = True
for e, c in info[start]:
cost[e] = min(cost[e], c) #μ¬λ¬ κ²½λ‘κ° μμ κ²½μ° μ΅μκ°μΌλ‘ μ΄κΈ°ν
for i in range(n-1):
node = get_min_cost_node()
visited[node] = True
for e, c in info[node]:
if cost[e] > cost[node] + c:
cost[e] = cost[node] + c
path[e] = path[node] + [node]
if start_city == end_city:
print(0)
print(1)
print(start_city)
else:
Dijikstra(start_city)
print(cost[end_city])
path[end_city] = [start_city] + path[end_city] + [end_city]
print(len(path[end_city]))
print(" ".join(map(str, path[end_city])))
λ€μ΅μ€νΈλΌμ 무μ γ γ γ γ γ γ γ γ γ |
π λ¬Έμ λ§ν¬
μ΅μλΉμ© ꡬνκΈ° 2
βοΈ μμλ μκ°
30λΆ
β¨ μλ μ½λ
μκ³ λ¦¬μ¦,,, κ±°μ νλ¬λ§μ νΈλ κ² κ°λ€μ© (κ²½μ§λν μ μΈνꡬ!)
λ‘±νμλ Έμ¨μ λλ€!
μμνκ² κ³¨λ 2~3 μ€μμ λͺ¨μνλ€κ° λ¬Έμ μ΄λ¦ λ³΄κ³ μ μ§ DP, 그리λ μΌ κ² κ°μμ 골λλλ° λ€λ₯Έ μκ³ λ¦¬μ¦μ΄μλ€μ ,,
λ¬Έμ λ λκ² κ°λ¨ν©λλ€.
μ μ§λ¬Έμ μ½μλ§μ, Aμμ Bλμλ‘ κ°λ λ²μ€ μ΅μ λΉμ©μ ꡬν΄λΌ λΌλ λ§μ 보μλ§μ λ€μ΅μ€νΈλΌ λΌλ κ²μ μ§κ°νμμ΅λλ€.
μ¬μ§μ΄ λ Έλμ κ°μλ 10λ§μ΄κ³ κ°μ μ κ°μκ° 1000 μ΄κΈ° λλ¬Έμ,$10λ§ * log(1000) = 100λ§$ μ΄λ―λ‘ μκ°λ³΅μ‘λλ μΈμ΄νμ΄μ£ !
λ§μμ λ¬Έμ κ·Έλ₯ λ€μ΅μ€νΈλΌ νλ©΄ ν립λλ€.
νμ§λ§ λ¬Έμ λ μ¬κΈ°μ ν κ°μ§ νΈλ¦μ λ κ±Έμμ΄μ.
μΆλ ₯μμ μ΅μ λΉμ©μ κ°μ§λ κ²½λ‘μμ λμμ κ°μ λ° λμμ κ²½λ‘λ₯Ό μΆλ ₯ν΄μΌν΄μ.
μ΄κ±Έ μ²μ λ΄€μΌλ©΄ λν΄νμ μλ μμ΅λλ€,,
κ° λ Έλλ§λ€ νμ€ν 리λ₯Ό λͺ¨λ μ μ₯ν΄μΌνλ...?
νκ³ λ§μ΄μμ.νμ§λ§ μ λ #85 λ₯Ό λ°λ‘ λ μ¬λ¦΄ μ μμκ³ ,
ν΄λΉ λ Έλλ‘ κ° λ μ΄μ λ Έλλ§ κΈ°λ‘ν΄μ€ λ€, λ§μ§λ§μ λμ°©μ§μ μΌλ‘λΆν° μμ μ§μ κΉμ§ νκ³ νκ³ μ¬λΌκ°λ©΄ μμ±μ λλ€!
μ΄ λ¬Έμ ,, μ²μ μ νλ©΄ μ‘°κΈ λΉν©μ€λ¬μΈ μλ μμ κ² κ°μμ.
νμ£Όλ λͺλΆ κ±Έλ Έλμ§ λ§ν΄μ£ΌμΈμ©~!!!!
π μλ‘κ² μκ²λ λ΄μ©