<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>백준 1446 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/%eb%b0%b1%ec%a4%80-1446/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Thu, 28 Mar 2024 11:44:31 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>백준 1446 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 1446번 (지름길, C++, Dijkstra) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1446%eb%b2%88-%ec%a7%80%eb%a6%84%ea%b8%b8-c-dijkstra-baekjoon/5322/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1446%eb%b2%88-%ec%a7%80%eb%a6%84%ea%b8%b8-c-dijkstra-baekjoon/5322/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 23 Jan 2023 09:23:15 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1446]]></category>
		<category><![CDATA[1446번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Dijkstra]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[길찾기]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[다익스트라]]></category>
		<category><![CDATA[데이크스트라]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1446]]></category>
		<category><![CDATA[백준 1446번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[지름길]]></category>
		<category><![CDATA[컴파일 에러]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[틀렸습니다]]></category>
		<category><![CDATA[틀렸습니다!]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5322</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1446번 '지름길' 문제에 대한 글입니다. 'Dijkstra' 알고리즘을 이용하여 해결하였습니다. (백준(BAEKJOON) 1446번 '지름길' 문제에 대한 글입니다. 'Dijkstra' 알고리즘을 이용하여 해결하였습니다. (BAEKJOON 1446 This is about the 'shortcut' problem, solved using the 'Dijkstra' algorithm.))</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1446%eb%b2%88-%ec%a7%80%eb%a6%84%ea%b8%b8-c-dijkstra-baekjoon/5322/">백준 1446번 (지름길, C++, Dijkstra) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">지름길</h1>



<p class="has-medium-font-size wp-block-paragraph"><a href="https://www.acmicpc.net/problem/1446" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1446</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">5137</td><td class="has-text-align-left" data-align="left">2633</td><td class="has-text-align-left" data-align="left">1998</td><td class="has-text-align-left" data-align="left">50.995%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size wp-block-paragraph">매일 아침, 세준이는 학교에 가기 위해서 차를 타고 D킬로미터 길이의 고속도로를 지난다. </p>



<p class="has-medium-font-size wp-block-paragraph">이 고속도로는 심각하게 커브가 많아서 정말 운전하기도 힘들다. </p>



<p class="has-medium-font-size wp-block-paragraph">어느 날, 세준이는 이 고속도로에 지름길이 존재한다는 것을 알게 되었다. </p>



<p class="has-medium-font-size wp-block-paragraph">모든 지름길은 일방통행이고, 고속도로를 역주행할 수는 없다.</p>



<p class="has-medium-font-size wp-block-paragraph">세준이가 운전해야 하는 거리의 최솟값을 출력하시오.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size wp-block-paragraph">첫째 줄에 지름길의 개수 N과 고속도로의 길이 D가 주어진다. </p>



<p class="has-medium-font-size wp-block-paragraph">N은 12 이하인 양의 정수이고, D는 10,000보다 작거나 같은 자연수이다. </p>



<p class="has-medium-font-size wp-block-paragraph">다음 N개의 줄에 지름길의 시작 위치, 도착 위치, 지름길의 길이가 주어진다. </p>



<p class="has-medium-font-size wp-block-paragraph">모든 위치와 길이는 10,000보다 작거나 같은 음이 아닌 정수이다. </p>



<p class="has-medium-font-size wp-block-paragraph">지름길의 시작 위치는 도착 위치보다 작다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size wp-block-paragraph">세준이가 운전해야하는 거리의 최솟값을 출력하시오.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 150
0 50 10
0 50 20
50 100 10
100 151 10
110 140 90</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">70</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2 100
10 60 40
50 90 20</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">80</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">8 900
0 10 9
20 60 45
80 190 100
50 70 15
160 180 14
140 160 14
420 901 5
450 900 0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">432</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<ul class="wp-block-list">
<li>문제를 번역한 사람:&nbsp;<a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>문제를 다시 작성한 사람:&nbsp;<a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/25" target="_blank" rel="noreferrer noopener">다이나믹 프로그래밍</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/7" target="_blank" rel="noreferrer noopener">그래프 이론</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/22" target="_blank" rel="noreferrer noopener">데이크스트라</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<p class="has-medium-font-size wp-block-paragraph">기본적인 로직은 Dujkstra 알고리즘을 기반으로 한다. </p>



<figure class="wp-block-embed is-type-wp-embed"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="VztkgwMIoE"><a href="https://lycos7560.com/?p=5223">알고리즘 &#8211; 다익스트라/데이크스트라(Dijkstra) 알고리즘 정리 (길찾기)</a></blockquote><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;알고리즘 &#8211; 다익스트라/데이크스트라(Dijkstra) 알고리즘 정리 (길찾기)&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="https://lycos7560.com/?p=5223&#038;embed=true#?secret=rNOzQBw4eP#?secret=VztkgwMIoE" data-secret="VztkgwMIoE" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<figure class="wp-block-image size-full is-resized"><img fetchpriority="high" decoding="async" width="721" height="463" src="https://lycos7560.com/wp-content/uploads/image-1034.png" alt="" class="wp-image-5326" style="width:945px;height:607px" srcset="https://lycos7560.com/wp-content/uploads/image-1034.png 721w, https://lycos7560.com/wp-content/uploads/image-1034-300x193.png 300w" sizes="(max-width: 721px) 100vw, 721px" /></figure>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">주의사항</h2>



<p class="has-medium-font-size wp-block-paragraph">주의할 점은 역주행이 불가능하다는 점 (현재 위치에서 지름길을 더한 값이 목적지를 넘어가면 안된다.)</p>



<p class="has-medium-font-size wp-block-paragraph">또 지름길이 순서대로 이쁘게 주어지지 않는다. (정렬을 해서 처리하는 것도 하나의 방법)</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">내 풀이는 최단경로 테이블을 갱신하면 목적지 그 이후의 값을  dist[]가 더 적거나 목적지까지 +1 해주면서 업데이트 해주었다. </p>



<div style="height:54px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="745" height="439" src="https://lycos7560.com/wp-content/uploads/image-1035.png" alt="" class="wp-image-5328" style="width:867px;height:511px" srcset="https://lycos7560.com/wp-content/uploads/image-1035.png 745w, https://lycos7560.com/wp-content/uploads/image-1035-300x177.png 300w" sizes="(max-width: 745px) 100vw, 745px" /></figure>



<div style="height:63px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">통과된 코드</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;vector>

using namespace std;

constexpr int MAXN = 10001;

// 지름길의 개수 N, 고속도로의 길이 D
int N, D;

int A, B, C;

/*
각 노드에 연결되어 있는 노드에 대한 정보를 담는 벡터
a번 노드에서 b번 노드로 가는 비용이 c라는 의미
graph[a].push_back({b, c});
*/
vector&lt;pair&lt;int, int>> graph[MAXN];

// 임시 노드
int dist[MAXN];

int main()
{
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	// scanf와 동기화를 비활성화
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> D;

	for (int i = 0; i &lt; N; i++) {
		cin >> A >> B >> C;
		graph[A].push_back(make_pair(B, C));
	}

	// 기본 초기화
	for (int i = 0; i &lt; MAXN; i++) dist[i] = i;

	int now = 0;
	while (true) {

		if (now == D) { 
			// 목적지에 도착했으므로 결과를 출력
			cout &lt;&lt; dist[now];
			break;
		}

		// 해당 노드에서 연결된 모든 경로를 확인
        for (int i = 0; i &lt; graph[now].size(); i++) {

            // disSum = 임시 노드 + 현재 노드에서 i로가는 비용
            int disSum = dist[now] + graph[now][i].second;
			
			// 역주행을 해야할 경우는 continue
			if (disSum > D) continue; 


            // 비용이 더 작다면 최단경로 테이블 값을 갱신.
            if (disSum &lt; dist[graph[now][i].first]) {
                // 임시 노드 업데이트
				dist[graph[now][i].first] = disSum;

				// 만약 업데이트 했다면 그 이후의 정점들을 순차적으로 올려준다.
				for (int j = graph[now][i].first + 1; j &lt;= D ; j++) {
					// 만약  dist[j]이 더 작거나 같다면 최단거리가 있다는 의미 => Break
					if (disSum >= dist[j]) break;
					else dist[j] = ++disSum;
				}
            }
        }

		now++;
	}

	return 0;
}</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1039" height="138" src="https://lycos7560.com/wp-content/uploads/image-1032.png" alt="" class="wp-image-5323" srcset="https://lycos7560.com/wp-content/uploads/image-1032.png 1039w, https://lycos7560.com/wp-content/uploads/image-1032-300x40.png 300w, https://lycos7560.com/wp-content/uploads/image-1032-768x102.png 768w" sizes="(max-width: 1039px) 100vw, 1039px" /></figure>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size wp-block-paragraph">dijkstra 알고리즘이 익숙하지 않아 해결하는데 오래 걸렸다&#8230;</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1446%eb%b2%88-%ec%a7%80%eb%a6%84%ea%b8%b8-c-dijkstra-baekjoon/5322/">백준 1446번 (지름길, C++, Dijkstra) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1446%eb%b2%88-%ec%a7%80%eb%a6%84%ea%b8%b8-c-dijkstra-baekjoon/5322/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
