Notice
														
												
											
												
												
													Recent Posts
													
											
												
												
													Recent Comments
													
											
												
												
													Link
													
											
									| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
													Tags
													
											
												
												- 이진탐색
 - 영어회화
 - 오픽가격
 - 메모이제이션
 - dp
 - 피보나치수열
 - 오픽노잼공부방법
 - fibo
 - stack 스택
 - topdown
 - 오픽점수잘받는방법
 - 안드로이드
 - 바텀업
 - 오픽공부법
 - 안드로이드주석
 - XML
 - 오픽
 - ㅂ
 - English
 - 영어말하기
 - opic
 - 디피
 - 다이나믹프로그래밍
 - 주석
 - XML주석
 - 탑다운
 - 이진탐색 #나무 자르기
 - dynamicProgramming
 - 오픽노잼
 
													Archives
													
											
									RUBY
전보 본문
출처:: 유명알고리즘 대회
분류::
1. 문제 이해 및 해결과정
| - 메세지를 보내고자 하는 도시 C가 출발점이 된다. | 
#input
3 2 1
1 2 4
1 3 2
#output
2 4
2. 풀이방법
1.다익스트라
#전보
#
import sys
import heapq
sys.stdin = open("input.txt","r")
input=sys.stdin.readline
n,m,start=map(int,input().split())
graph=[[] for _ in range(n+1)]
INF=1e9
dist=[INF]*(n+1)
visited=[False]*(n+1)
for _ in range(m):
    x,y,z=map(int,input().split()) #x에서 y로 이어지는 통로에서 메세지 전달시간이z
    graph[x].append((y,z))
def dijkstra(start):
    dist[start]=0
    visited[start]=True
    q=[]
    heapq.heappush(q,(0,start))
    while q:
        c,cur=heapq.heappop(q)
        if dist[cur]<c:
            continue
        for i in graph[cur]:
            cost=dist[cur]+i[1]
            if dist[i[0]]>cost:
                dist[i[0]]=cost
                heapq.heappush(q,(cost,i[0]))
dijkstra(start)
print(dist)
cnt=0
sol=0
for d in dist:
    if d!=INF:
        cnt+=1
        sol=max(sol,d)
print('%d %d' %(cnt-1,sol)) #시작노드 제외해야하므로 cnt-1
3. 오답원인
4. 알게된 점
'PS > This' 카테고리의 다른 글
| [백준] 숨박꼭질 (0) | 2020.09.26 | 
|---|---|
| [이론] 구간 합(Prefix sum) (0) | 2020.09.19 | 
| [이론] 이진탐색 / 파라메트릭서치 (0) | 2020.09.18 | 
| [백준] 최종 순위 (0) | 2020.09.15 | 
| 만들 수 없는 금액 (0) | 2020.09.13 | 
			  Comments