<?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>골드 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/%EA%B3%A8%EB%93%9C/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Wed, 15 Oct 2025 05:34:59 +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>골드 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 1240번 (노드사이의 거리, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-1240%eb%b2%88-%eb%85%b8%eb%93%9c%ec%82%ac%ec%9d%b4%ec%9d%98-%ea%b1%b0%eb%a6%ac-c-baekjoon/37874/</link>
					<comments>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-1240%eb%b2%88-%eb%85%b8%eb%93%9c%ec%82%ac%ec%9d%b4%ec%9d%98-%ea%b1%b0%eb%a6%ac-c-baekjoon/37874/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 04 Mar 2024 15:51:29 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1240]]></category>
		<category><![CDATA[1240 C++]]></category>
		<category><![CDATA[1240번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[dfs]]></category>
		<category><![CDATA[Gold]]></category>
		<category><![CDATA[Gold5]]></category>
		<category><![CDATA[Recursive]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[골드]]></category>
		<category><![CDATA[골드5]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[깊이]]></category>
		<category><![CDATA[깊이 우선 탐색]]></category>
		<category><![CDATA[노드사이의 거리]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1240]]></category>
		<category><![CDATA[백준 1240번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[재귀]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=37874</guid>

					<description><![CDATA[<p>백준 온라인 문제 1240번 문제에 대한 글입니다.<br />
DFS 재귀 함수를 사용하여 해결하였습니다.  (This is about question 1240 of Baekjun Online Problem.<br />
Resolved using the DFS recursive function.)</p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-1240%eb%b2%88-%eb%85%b8%eb%93%9c%ec%82%ac%ec%9d%b4%ec%9d%98-%ea%b1%b0%eb%a6%ac-c-baekjoon/37874/">백준 1240번 (노드사이의 거리, C++) [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>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-75779d84      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#노드사이의-거리" class="uagb-toc-link__trigger">노드사이의 거리</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ol>					</div>
									</div>
				</div>
			


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



<h2 class="wp-block-heading">노드사이의 거리 <img decoding="async" width="30" height="38" class="wp-image-37889" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Gold_5.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Gold_5.jpg 1250w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-234x300.jpg 234w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-768x983.jpg 768w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-1200x1536.jpg 1200w" sizes="(max-width: 30px) 100vw, 30px" /></h2>



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



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



<figure 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">9018</td><td class="has-text-align-left" data-align="left">4874</td><td class="has-text-align-left" data-align="left">3752</td><td class="has-text-align-left" data-align="left">53.638%</td></tr></tbody></table></figure>



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



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



<p class="wp-block-paragraph"> N개의 노드로 이루어진 트리가 주어지고 M개의 두 노드 쌍을 입력받을 때 두 노드 사이의 거리를 출력하라.</p>



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



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



<p class="wp-block-paragraph">첫째 줄에 노드의 개수&nbsp;N과 거리를 알고 싶은 노드 쌍의 개수&nbsp;M이 입력되고 다음&nbsp;N-1개의 줄에 트리 상에 연결된 두 점과 거리를 입력받는다. </p>



<p class="wp-block-paragraph">그 다음 줄에는 거리를 알고 싶은&nbsp;M개의 노드 쌍이 한 줄에 한 쌍씩 입력된다.</p>



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



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



<p class="wp-block-paragraph"> M개의 줄에 차례대로 입력받은 두 노드 사이의 거리를 출력한다.</p>



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



<h3 class="wp-block-heading">제한</h3>



<ul class="wp-block-list">
<li> 2 ≤ N ≤1,000 </li>



<li> 1 ≤ M ≤ 1,000 </li>



<li>트리 상에 연결된 두 점과 거리는&nbsp;10,000&nbsp;이하인 자연수이다.</li>



<li>트리 노드의 번호는&nbsp;1부터&nbsp;N까지 자연수이며, 두 노드가 같은 번호를 갖는 경우는 없다.</li>
</ul>



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



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<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="">4 2
2 1 2
4 3 2
1 4 3
1 2
3 2</pre>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<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
7</pre>
</div>
</div>



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



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



<ul class="wp-block-list">
<li>빠진 조건을 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/hg7258" target="_blank" rel="noreferrer noopener">hg7258</a></li>
</ul>



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



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



<ul class="wp-block-list">
<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/11" target="_blank" rel="noreferrer noopener">그래프 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/120" target="_blank" rel="noreferrer noopener">트리</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/126" target="_blank" rel="noreferrer noopener">너비 우선 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/127" 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)"/>



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



<p class="wp-block-paragraph">DFS를 이용하여 탐색</p>



<p class="wp-block-paragraph">리펙토링하면 메모리와 시간을 더 줄일 수 있음</p>



<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 MAX = 1001;

int N, M, _End;

vector&lt;int> Nodes[MAX];
vector&lt;int> Distances[MAX][MAX];
bool IsVisted[MAX];


void DFS(int _Len, int _CurNode)
{
	if (_End == _CurNode) {
		cout &lt;&lt; _Len &lt;&lt; '\n';
		return;
	}

	for (int i = 0; i &lt; Nodes[_CurNode].size(); i++)
	{
		int NextNode = Nodes[_CurNode][i];
		if (IsVisted[NextNode]) 
			continue;
		IsVisted[NextNode] = true;
		DFS(_Len + *Distances[_CurNode][NextNode].begin(), NextNode);
		IsVisted[NextNode] = false;
	}

}

int main()
{
	cin >> N >> M;
	int _S, _E, _D;
	for (int i = 0; i &lt; N-1; i++) {
		cin >> _S >> _E >> _D;
		Nodes[_S].push_back(_E);
		Nodes[_E].push_back(_S);
		Distances[_S][_E].push_back(_D);
		Distances[_E][_S].push_back(_D);
	}

	for (int i = 0; i &lt; M; i++) {
		cin >> _S >> _E;
		_End = _E;
		IsVisted[_S] = true;
		DFS(0, _S);
		IsVisted[_S] = false;
	}


	return 0;
}</pre>



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



<p class="wp-block-paragraph">방문 체크를 빼먹어서 틀렸다.</p>



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



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="830" height="120" src="https://lycos7560.com/wp-content/uploads/2024/03/image.png" alt="" class="wp-image-37875" srcset="https://lycos7560.com/wp-content/uploads/2024/03/image.png 830w, https://lycos7560.com/wp-content/uploads/2024/03/image-300x43.png 300w, https://lycos7560.com/wp-content/uploads/2024/03/image-768x111.png 768w" sizes="(max-width: 830px) 100vw, 830px" /></figure>



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



<p class="wp-block-paragraph">추가</p>



<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="">    ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
    cin.tie(NULL);
    cout.tie(NULL);</pre>



<div style="height:40px" 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 MAX = 1001;

int N, M, _End;

vector&lt;int> Nodes[MAX];
vector&lt;int> Distances[MAX][MAX];
bool IsVisted[MAX];


void DFS(int _Len, int _CurNode)
{
	if (_End == _CurNode) {
		cout &lt;&lt; _Len &lt;&lt; '\n';
		return;
	}

	for (int i = 0; i &lt; Nodes[_CurNode].size(); i++)
	{
		int NextNode = Nodes[_CurNode][i];
		if (IsVisted[NextNode]) 
			continue;
		IsVisted[NextNode] = true;
		DFS(_Len + *Distances[_CurNode][NextNode].begin(), NextNode);
		IsVisted[NextNode] = false;
	}

}

int main()
{
    ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
    cin.tie(NULL);
    cout.tie(NULL);
	cin >> N >> M;
	int _S, _E, _D;
	for (int i = 0; i &lt; N-1; i++) {
		cin >> _S >> _E >> _D;
		Nodes[_S].push_back(_E);
		Nodes[_E].push_back(_S);
		Distances[_S][_E].push_back(_D);
		Distances[_E][_S].push_back(_D);
	}

	for (int i = 0; i &lt; M; i++) {
		cin >> _S >> _E;
		_End = _E;
		IsVisted[_S] = true;
		DFS(0, _S);
		IsVisted[_S] = false;
	}


	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="834" height="84" src="https://lycos7560.com/wp-content/uploads/2024/03/image-1.png" alt="" class="wp-image-37877" srcset="https://lycos7560.com/wp-content/uploads/2024/03/image-1.png 834w, https://lycos7560.com/wp-content/uploads/2024/03/image-1-300x30.png 300w, https://lycos7560.com/wp-content/uploads/2024/03/image-1-768x77.png 768w" sizes="(max-width: 834px) 100vw, 834px" /></figure>



<div style="height:40px" 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="4386247858"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-1240%eb%b2%88-%eb%85%b8%eb%93%9c%ec%82%ac%ec%9d%b4%ec%9d%98-%ea%b1%b0%eb%a6%ac-c-baekjoon/37874/">백준 1240번 (노드사이의 거리, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-1240%eb%b2%88-%eb%85%b8%eb%93%9c%ec%82%ac%ec%9d%b4%ec%9d%98-%ea%b1%b0%eb%a6%ac-c-baekjoon/37874/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2146번 (다리 만들기, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2146%eb%b2%88-%eb%8b%a4%eb%a6%ac-%eb%a7%8c%eb%93%a4%ea%b8%b0-c-baekjoon/37865/</link>
					<comments>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2146%eb%b2%88-%eb%8b%a4%eb%a6%ac-%eb%a7%8c%eb%93%a4%ea%b8%b0-c-baekjoon/37865/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 25 Feb 2024 00:23:34 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2146]]></category>
		<category><![CDATA[2146번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Gold]]></category>
		<category><![CDATA[Gold3]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[골드]]></category>
		<category><![CDATA[골드3]]></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[백준 2146]]></category>
		<category><![CDATA[백준 2146번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=37865</guid>

					<description><![CDATA[<p>백준 2146번 '다리 만들기' 문제에 대한 글입니다. BFS를 이용하여 섬을 구분해준 이후에 다시 BFS로 섬간의 최단 거리를 구하여 문제를 해결하였습니다. (This is about the issue of 'Building a Bridge' BaekJoon No. 2146. After classifying the islands using BFS, we solved the problem by finding the shortest distance between the islands again with BFS.)</p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2146%eb%b2%88-%eb%8b%a4%eb%a6%ac-%eb%a7%8c%eb%93%a4%ea%b8%b0-c-baekjoon/37865/">백준 2146번 (다리 만들기, C++) [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>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-75779d84      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#다리-만들기" class="uagb-toc-link__trigger">다리 만들기</a><li class="uagb-toc__list"><a href="#추가-반례" class="uagb-toc-link__trigger">추가 반례</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ol>					</div>
									</div>
				</div>
			


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



<h2 class="wp-block-heading">다리 만들기 <img decoding="async" width="30" height="38" class="wp-image-37891" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/02/Gold_3.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/02/Gold_3.jpg 1250w, https://lycos7560.com/wp-content/uploads/2024/02/Gold_3-234x300.jpg 234w, https://lycos7560.com/wp-content/uploads/2024/02/Gold_3-768x983.jpg 768w, https://lycos7560.com/wp-content/uploads/2024/02/Gold_3-1200x1536.jpg 1200w" sizes="(max-width: 30px) 100vw, 30px" /></h2>



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



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



<figure 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">192 MB</td><td class="has-text-align-left" data-align="left">42718</td><td class="has-text-align-left" data-align="left">15973</td><td class="has-text-align-left" data-align="left">9991</td><td class="has-text-align-left" data-align="left">34.260%</td></tr></tbody></table></figure>



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



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



<p class="wp-block-paragraph">여러 섬으로 이루어진 나라가 있다. </p>



<p class="wp-block-paragraph">이 나라의 대통령은 섬을 잇는 다리를 만들겠다는 공약으로 인기몰이를 해 당선될 수 있었다. </p>



<p class="wp-block-paragraph">하지만 막상 대통령에 취임하자, 다리를 놓는다는 것이 아깝다는 생각을 하게 되었다. </p>



<p class="wp-block-paragraph">그래서 그는, 생색내는 식으로 한 섬과 다른 섬을 잇는 다리 하나만을 만들기로 하였고, 그 또한 다리를 가장 짧게 하여 돈을 아끼려 하였다.</p>



<p class="wp-block-paragraph">이 나라는 N×N크기의 이차원 평면상에 존재한다. 이 나라는 여러 섬으로 이루어져 있으며, 섬이란 동서남북으로 육지가 붙어있는 덩어리를 말한다. </p>



<p class="wp-block-paragraph">다음은 세 개의 섬으로 이루어진 나라의 지도이다.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="302" height="284" src="https://lycos7560.com/wp-content/uploads/2024/02/image-1.png" alt="" class="wp-image-37866" srcset="https://lycos7560.com/wp-content/uploads/2024/02/image-1.png 302w, https://lycos7560.com/wp-content/uploads/2024/02/image-1-300x282.png 300w" sizes="(max-width: 302px) 100vw, 302px" /></figure>



<p class="wp-block-paragraph">위의 그림에서 색이 있는 부분이 육지이고, 색이 없는 부분이 바다이다. </p>



<p class="wp-block-paragraph">이 바다에 가장 짧은 다리를 놓아 두 대륙을 연결하고자 한다. </p>



<p class="wp-block-paragraph">가장 짧은 다리란, 다리가 격자에서 차지하는 칸의 수가 가장 작은 다리를 말한다. </p>



<p class="wp-block-paragraph">다음 그림에서 두 대륙을 연결하는 다리를 볼 수 있다.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="301" height="271" src="https://lycos7560.com/wp-content/uploads/2024/02/image-3.png" alt="" class="wp-image-37868"/></figure>



<p class="wp-block-paragraph">물론 위의 방법 외에도 다리를 놓는 방법이 여러 가지 있으나, 위의 경우가 놓는 다리의 길이가 3으로 가장 짧다</p>



<p class="wp-block-paragraph">(물론 길이가 3인 다른 다리를 놓을 수 있는 방법도 몇 가지 있다).</p>



<p class="wp-block-paragraph">지도가 주어질 때, 가장 짧은 다리 하나를 놓아 두 대륙을 연결하는 방법을 찾으시오.</p>



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



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



<p class="wp-block-paragraph">첫 줄에는 지도의 크기 N(100이하의 자연수)가 주어진다. </p>



<p class="wp-block-paragraph">그 다음 N줄에는 N개의 숫자가 빈칸을 사이에 두고 주어지며, 0은 바다, 1은 육지를 나타낸다. </p>



<p class="wp-block-paragraph">항상 두 개 이상의 섬이 있는 데이터만 입력으로 주어진다.</p>



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



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



<p class="wp-block-paragraph">첫째 줄에 가장 짧은 다리의 길이를 출력한다.</p>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<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="">10
1 1 1 0 0 0 0 1 1 1
1 1 1 1 0 0 0 0 1 1
1 0 1 1 0 0 0 0 1 1
0 0 1 1 1 0 0 0 0 1
0 0 0 1 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 0 0 0 0
0 0 0 0 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<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="">3</pre>



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



<h2 class="wp-block-heading has-large-font-size">추가 반례</h2>



<p class="wp-block-paragraph"><a href="https://www.acmicpc.net/board/search/all/problem/2146" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/board/search/all/problem/2146</a></p>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 A</h3>



<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="">4
1 0 0 1
0 0 0 0
0 1 1 0
0 0 0 0</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 A</h3>



<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</pre>



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



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 B</h3>



<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="">6
1 0 0 1 1 1
1 0 0 0 0 1
1 0 0 0 0 0
1 0 0 0 0 1
1 1 1 1 1 1
0 0 0 0 0 0</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 B</h3>



<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="">1</pre>



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



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 C</h3>



<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="">4
1 0 0 0
0 0 0 0
0 0 0 1
0 0 0 1</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 C</h3>



<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="">4</pre>



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



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



<ul class="wp-block-list">
<li>빠진 조건을 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/choiking10">cho</a><a href="https://www.acmicpc.net/user/choiking10" target="_blank" rel="noreferrer noopener">i</a><a href="https://www.acmicpc.net/user/choiking10">king10</a></li>



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/hello70825" target="_blank" rel="noreferrer noopener">hello70825</a>,&nbsp;<a href="https://www.acmicpc.net/user/ohyuni" target="_blank" rel="noreferrer noopener">ohyuni</a></li>



<li>잘못된 데이터를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/tncks0121" target="_blank" rel="noreferrer noopener">tncks0121</a></li>
</ul>



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



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



<ul class="wp-block-list">
<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/11" target="_blank" rel="noreferrer noopener">그래프 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/126" 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)"/>



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



<p class="wp-block-paragraph">1. 맵을 순회하면서 BFS를 이용하여 섬을 구분</p>



<p class="wp-block-paragraph">2. 섬마다 가장 가까운 다른 섬까지의 거리를 구함</p>



<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;queue>

using namespace std;

constexpr int MAX = 100;
int _QSize;

int _MAP[MAX][MAX];
bool _IsVisted[MAX][MAX];

int DxDy[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };

void ClearMap()
{
	for (int i = 0; i &lt; _QSize; i++)
		for (int j = 0; j &lt; _QSize; j++) {
			_IsVisted[i][j] = false;
			if (_MAP[i][j] &lt;= 0)
				_MAP[i][j] = 0;
		}

}

void SortOutTypesIslands(const int _cntSort, const int _startI, const int _startJ)
{
	queue&lt;pair&lt;int, int>> SortQueue;
	SortQueue.push({ _startI, _startJ });
	_MAP[_startI][_startJ] = _cntSort;
	while (!SortQueue.empty())
	{
		pair&lt;int, int> _cntXY = SortQueue.front();
		SortQueue.pop();

		for (int i = 0; i &lt; 4; i++) {
			int _Tx = _cntXY.first + DxDy[i][0];
			int _Ty = _cntXY.second + DxDy[i][1];

			if (_Tx >= _QSize || _Ty >= _QSize || _Tx &lt; 0 || _Ty &lt; 0)
				continue;
			
			if (_MAP[_Tx][_Ty] == 1) {
				_MAP[_Tx][_Ty] = _cntSort;
				SortQueue.push({ _Tx, _Ty });
			}

		}

	}
}


int FindShortBridge(queue&lt;pair&lt;int, int>>&amp; TypeQueue, const int _cntType)
{
	int _shortLen = INT32_MAX;

	while (!TypeQueue.empty())
	{
		pair&lt;int, int> _cntXY = TypeQueue.front();
		TypeQueue.pop();

		int _cnt;
		if (_MAP[_cntXY.first][_cntXY.second] == _cntType) _cnt = 0;
		else _cnt = _MAP[_cntXY.first][_cntXY.second];

		for (int i = 0; i &lt; 4; i++) {
			int _Tx = _cntXY.first + DxDy[i][0];
			int _Ty = _cntXY.second + DxDy[i][1];

			if (_Tx >= _QSize || _Ty >= _QSize || _Tx &lt; 0 || _Ty &lt; 0 || _IsVisted[_Tx][_Ty])
				continue;

			if (_MAP[_Tx][_Ty] != _cntType &amp;&amp; _MAP[_Tx][_Ty] >= 1) {
				if (_shortLen > -_cnt) 
					_shortLen = -_cnt;
				break;
			}

			if (_MAP[_Tx][_Ty] == 0) {
				TypeQueue.push({ _Tx, _Ty });
				_IsVisted[_Tx][_Ty] = true;
				_MAP[_Tx][_Ty] = _cnt - 1;

			}
		}

	}

	return _shortLen;
}


int main()
{ 
	int _res = INT32_MAX;
	cin >> _QSize;
	for (int i = 0; i &lt; _QSize; i++)
		for (int j = 0; j &lt; _QSize; j++)
			cin >> _MAP[i][j];

	int _Sort = 2;
	for (int i = 0; i &lt; _QSize; i++)
		for (int j = 0; j &lt; _QSize; j++)
			if (_MAP[i][j] == 1) {
				SortOutTypesIslands(_Sort, i, j);
				_Sort++;
			}

	while (_Sort != 1)
	{
		queue&lt;pair&lt;int, int>> TypeQueue;
		for (int i = 0; i &lt; _QSize; i++)
			for (int j = 0; j &lt; _QSize; j++)
				if (_MAP[i][j] == _Sort) {
					TypeQueue.push({ i, j });
					_IsVisted[i][j] = true;
				}

		ClearMap();
		_res = min(_res, FindShortBridge(TypeQueue, _Sort));
		_Sort--;
	}

	cout &lt;&lt; _res;

	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="1201" height="51" src="https://lycos7560.com/wp-content/uploads/2024/02/image-4.png" alt="" class="wp-image-37869" srcset="https://lycos7560.com/wp-content/uploads/2024/02/image-4.png 1201w, https://lycos7560.com/wp-content/uploads/2024/02/image-4-300x13.png 300w, https://lycos7560.com/wp-content/uploads/2024/02/image-4-768x33.png 768w" sizes="(max-width: 1201px) 100vw, 1201px" /></figure>



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



<p class="wp-block-paragraph">섬의 좌표를 구분단계에서 미리 저장하여 비효율적인 부분을 제거</p>



<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;queue>

using namespace std;

constexpr int MAX = 100;
int _QSize;

int _MAP[MAX][MAX];
bool _IsVisted[MAX][MAX];

int DxDy[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };

void ClearMap()
{
	for (int i = 0; i &lt; _QSize; i++)
		for (int j = 0; j &lt; _QSize; j++) {
			_IsVisted[i][j] = false;
			if (_MAP[i][j] &lt;= 0)
				_MAP[i][j] = 0;
		}

}

queue&lt;pair&lt;unsigned char, unsigned char>> SortOutTypesIslands(const int _cntSort, const int _startI, const int _startJ)
{
	queue&lt;pair&lt;unsigned char, unsigned char>> TotalPosQueue;

	queue&lt;pair&lt;int, int>> SortQueue;
	SortQueue.push({ _startI, _startJ });
	TotalPosQueue.push({ _startI, _startJ });
	_MAP[_startI][_startJ] = _cntSort;
	while (!SortQueue.empty())
	{
		pair&lt;int, int> _cntXY = SortQueue.front();
		SortQueue.pop();

		for (int i = 0; i &lt; 4; i++) {
			int _Tx = _cntXY.first + DxDy[i][0];
			int _Ty = _cntXY.second + DxDy[i][1];

			if (_Tx >= _QSize || _Ty >= _QSize || _Tx &lt; 0 || _Ty &lt; 0)
				continue;

			if (_MAP[_Tx][_Ty] == 1) {
				_MAP[_Tx][_Ty] = _cntSort;
				SortQueue.push({ _Tx, _Ty });
				TotalPosQueue.push({ _Tx, _Ty });
			}

		}

	}

	return TotalPosQueue;
}


int FindShortBridge(queue&lt;pair&lt;unsigned char, unsigned char>>&amp; TypeQueue, const int _cntType)
{
	int _shortLen = INT32_MAX;

	while (!TypeQueue.empty())
	{
		pair&lt;int, int> _cntXY = TypeQueue.front();
		TypeQueue.pop();

		int _cnt;
		if (_MAP[_cntXY.first][_cntXY.second] == _cntType) _cnt = 0;
		else _cnt = _MAP[_cntXY.first][_cntXY.second];

		for (int i = 0; i &lt; 4; i++) {
			int _Tx = _cntXY.first + DxDy[i][0];
			int _Ty = _cntXY.second + DxDy[i][1];

			if (_Tx >= _QSize || _Ty >= _QSize || _Tx &lt; 0 || _Ty &lt; 0 || _IsVisted[_Tx][_Ty])
				continue;

			if (_MAP[_Tx][_Ty] != _cntType &amp;&amp; _MAP[_Tx][_Ty] >= 1) {
				if (_shortLen > -_cnt)
					_shortLen = -_cnt;
				break;
			}

			if (_MAP[_Tx][_Ty] == 0) {
				TypeQueue.push({ _Tx, _Ty });
				_IsVisted[_Tx][_Ty] = true;
				_MAP[_Tx][_Ty] = _cnt - 1;

			}
		}

	}

	return _shortLen;
}


int main()
{
	int _res = INT32_MAX;
	queue&lt;queue&lt;pair&lt;unsigned char, unsigned char>>> TotalQueue;
	cin >> _QSize;
	for (int i = 0; i &lt; _QSize; i++)
		for (int j = 0; j &lt; _QSize; j++)
			cin >> _MAP[i][j];

	int _Sort = 2;
	for (int i = 0; i &lt; _QSize; i++)
		for (int j = 0; j &lt; _QSize; j++)
			if (_MAP[i][j] == 1) {
				TotalQueue.push(SortOutTypesIslands(_Sort, i, j));
				_Sort++;
			}

	while (!TotalQueue.empty())
	{
		queue&lt;pair&lt;unsigned char, unsigned char>> TypeQueue = TotalQueue.front();
		_Sort = _MAP[TypeQueue.front().first][TypeQueue.front().second];
		TotalQueue.pop();
		ClearMap();
		_res = min(_res, FindShortBridge(TypeQueue, _Sort));
	}

	cout &lt;&lt; _res;

	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="1035" height="53" src="https://lycos7560.com/wp-content/uploads/2024/02/image-5.png" alt="" class="wp-image-37870" srcset="https://lycos7560.com/wp-content/uploads/2024/02/image-5.png 1035w, https://lycos7560.com/wp-content/uploads/2024/02/image-5-300x15.png 300w, https://lycos7560.com/wp-content/uploads/2024/02/image-5-768x39.png 768w" sizes="(max-width: 1035px) 100vw, 1035px" /></figure>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1203" height="360" src="https://lycos7560.com/wp-content/uploads/2024/02/image-6.png" alt="" class="wp-image-37871" srcset="https://lycos7560.com/wp-content/uploads/2024/02/image-6.png 1203w, https://lycos7560.com/wp-content/uploads/2024/02/image-6-300x90.png 300w, https://lycos7560.com/wp-content/uploads/2024/02/image-6-768x230.png 768w" sizes="(max-width: 1203px) 100vw, 1203px" /></figure>



<div style="height:20px" 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="4386247858"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2146%eb%b2%88-%eb%8b%a4%eb%a6%ac-%eb%a7%8c%eb%93%a4%ea%b8%b0-c-baekjoon/37865/">백준 2146번 (다리 만들기, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2146%eb%b2%88-%eb%8b%a4%eb%a6%ac-%eb%a7%8c%eb%93%a4%ea%b8%b0-c-baekjoon/37865/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2042번 (구간 합 구하기, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2042%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-c-baekjoon/36648/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2042%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-c-baekjoon/36648/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 30 Aug 2023 16:26:47 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2042]]></category>
		<category><![CDATA[2042번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Gold]]></category>
		<category><![CDATA[Gold1]]></category>
		<category><![CDATA[Segment Tree]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[골드]]></category>
		<category><![CDATA[골드1]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구간 합 구하기]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2042]]></category>
		<category><![CDATA[백준 2042번]]></category>
		<category><![CDATA[세그먼트 트리]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36648</guid>

					<description><![CDATA[<p>백준 2042번 '구간 합 구하기' 문제에 대한 글입니다. '세그먼트 트리(Segment Tree)' 알고리즘을 이용하여 해결하였습니다. (This article is about Baekjoon Number 2042 'Summing the intervals' problem. It was solved using the 'Segment Tree' algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2042%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-c-baekjoon/36648/">백준 2042번 (구간 합 구하기, C++) [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>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-75779d84      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#구간-합-구하기" class="uagb-toc-link__trigger">구간 합 구하기</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#참고-자료" class="uagb-toc-link__trigger">참고 자료</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">구간 합 구하기 <img decoding="async" width="30" height="38" class="wp-image-37902" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Gold_1.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Gold_1.jpg 400w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_1-234x300.jpg 234w" sizes="(max-width: 30px) 100vw, 30px" /></h1>



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



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



<figure 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">256 MB</td><td class="has-text-align-left" data-align="left">86858</td><td class="has-text-align-left" data-align="left">20690</td><td class="has-text-align-left" data-align="left">10615</td><td class="has-text-align-left" data-align="left">24.949%</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p class="wp-block-paragraph">어떤 N개의 수가 주어져 있다. </p>



<p class="wp-block-paragraph">그런데 중간에 수의 변경이 빈번히 일어나고 그 중간에 어떤 부분의 합을 구하려 한다. </p>



<p class="wp-block-paragraph">만약에 1,2,3,4,5 라는 수가 있고, 3번째 수를 6으로 바꾸고 2번째부터 5번째까지 합을 구하라고 한다면 17을 출력하면 되는 것이다. </p>



<p class="wp-block-paragraph">그리고 그 상태에서 다섯 번째 수를 2로 바꾸고 3번째부터 5번째까지 합을 구하라고 한다면 12가 될 것이다.</p>



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



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p class="wp-block-paragraph">첫째 줄에 수의 개수 N(1 ≤ N ≤ 1,000,000)과 M(1 ≤ M ≤ 10,000), K(1 ≤ K ≤ 10,000) 가 주어진다. </p>



<p class="wp-block-paragraph">M은 수의 변경이 일어나는 횟수이고, K는 구간의 합을 구하는 횟수이다. </p>



<p class="wp-block-paragraph">그리고 둘째 줄부터 N+1번째 줄까지 N개의 수가 주어진다. </p>



<p class="wp-block-paragraph">그리고 N+2번째 줄부터 N+M+K+1번째 줄까지 세 개의 정수 a, b, c가 주어지는데, </p>



<p class="wp-block-paragraph">a가 1인 경우 b(1 ≤ b ≤ N)번째 수를 c로 바꾸고 </p>



<p class="wp-block-paragraph">a가 2인 경우에는 b(1 ≤ b ≤ N)번째 수부터 c(b ≤ c ≤ N)번째 수까지의 합을 구하여 출력하면 된다.</p>



<p class="wp-block-paragraph">입력으로 주어지는 모든 수는 -2<sup>63</sup>보다 크거나 같고, 2<sup>63</sup>-1보다 작거나 같은 정수이다.</p>



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



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p class="wp-block-paragraph">첫째 줄부터 K줄에 걸쳐 구한 구간의 합을 출력한다. </p>



<p class="wp-block-paragraph">단, 정답은 -2<sup>63</sup>보다 크거나 같고, 2<sup>63</sup>-1보다 작거나 같은 정수이다.</p>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<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 2 2
1
2
3
4
5
1 3 6
2 2 5
1 5 2
2 3 5</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<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="">17
12</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 A</h3>



<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="">1 1 2
5000000000000000000
2 1 1
1 1 -5000000000000000000
2 1 1</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 A</h3>



<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="">5000000000000000000
-5000000000000000000</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 B</h3>



<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 2 2
1
2
3
4
5
1 3 6
2 2 5
1 3 7
2 2 5</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 B</h3>



<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="">17
18</pre>



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



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<ul class="wp-block-list">
<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/79brue">79brue</a>,&nbsp;<a href="https://www.acmicpc.net/user/keunbum">keunbum</a>,&nbsp;<a href="https://www.acmicpc.net/user/Nyan101">Nyan101</a>,&nbsp;<a href="https://www.acmicpc.net/user/tncks0121">tncks0121</a></li>



<li>빠진 조건을 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/79brue">79brue</a>,&nbsp;<a href="https://www.acmicpc.net/user/djm03178">djm03178</a>,&nbsp;<a href="https://www.acmicpc.net/user/jh05013">jh05013</a></li>



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/eric00513">eric00513</a>,&nbsp;<a href="https://www.acmicpc.net/user/klm03025">klm03025</a>,&nbsp;<a href="https://www.acmicpc.net/user/yuja">yuja</a></li>



<li>잘못된 조건을 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/WeissBlume">WeissBlume</a></li>
</ul>



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



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/175" target="_blank" rel="noreferrer noopener">자료 구조</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/65" 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)"/>



<h2 class="wp-block-heading has-large-font-size">참고 자료</h2>



<p class="wp-block-paragraph">세그먼트 트리를 이해하는데 아래의 강의와 링크에 많은 도움을 받았다.</p>



<p class="wp-block-paragraph"><a href="https://blog.garybricks.com/segment-tree-introduction-in-c" target="_blank" rel="noreferrer noopener">https://blog.garybricks.com/segment-tree-introduction-in-c</a></p>



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



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio" style="max-width: 50%;">
  <div class="wp-block-embed__wrapper">
    <iframe loading="lazy" width="1120" height="630" src="https://www.youtube.com/embed/1d9sqmuLy-o" frameborder="0" allowfullscreen></iframe>
  </div>
</figure>



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



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



<p class="wp-block-paragraph">세그먼트 트리(Segment Tree)를 이용하여 구간합을 구하는 문제</p>



<div style="height:40px" 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>
using namespace std;
typedef long long ll;
int _N, _M, _K;
int _SegSize, _Num;
ll* _Numbers;
ll* _SegmentTree;

void InitSegTree()
{
    _Num = 1;
    while (_Num &lt; _N)
        _Num *= 2;
    _SegSize = _Num * 2;
    _SegmentTree = new ll[_SegSize]();
    for (int i = _Num, j = 0; j &lt; _N; j++)
        _SegmentTree[i + j] = _Numbers[j + 1];
    for (int i = _SegSize / 2 - 1; i > 0; i--)
        _SegmentTree[i] = _SegmentTree[i * 2] + _SegmentTree[i * 2 + 1];
}

void Update(int _Index, long long Value)
{
    _Index += _SegSize / 2 - 1;
    _SegmentTree[_Index] = Value;
    while (_Index != 0) {
        _Index /= 2;
        _SegmentTree[_Index] = _SegmentTree[_Index * 2] + _SegmentTree[_Index * 2 + 1];
    }
}

ll Sum(int _s, int _e)
{
    ll _Res = 0;
    while (_s &lt;= _e) {
        if (_s % 2 == 1)
            _Res += _SegmentTree[_s];
        if (_e % 2 == 0)
            _Res += _SegmentTree[_e];
        _s = (_s + 1) / 2;
        _e = (_e - 1) / 2;
    }
    return _Res;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> _N >> _M >> _K;
    _Numbers = new ll[_N + 1]();
    for (int i = 1; i &lt;= _N; i++)
        cin >> _Numbers[i];
    InitSegTree();

    ll _t1, _t2, _O;
    while (_M + _K > 0) {
        cin >> _O >> _t1 >> _t2;
        if (_O == 1) {
            Update(_t1, _t2);
            _M--;
        }
        else if (_O == 2) {
            cout &lt;&lt; Sum(_t1 + _Num - 1, _t2 + _Num - 1) &lt;&lt; "\n";
            _K--;
        }
    }
    return 0;
}
</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="1207" height="229" src="https://lycos7560.com/wp-content/uploads/2023/08/image-31.png" alt="" class="wp-image-36656" style="width:902px;height:171px" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-31.png 1207w, https://lycos7560.com/wp-content/uploads/2023/08/image-31-300x57.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-31-768x146.png 768w" sizes="(max-width: 1207px) 100vw, 1207px" /></figure>



<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="4386247858"></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-2042%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-c-baekjoon/36648/">백준 2042번 (구간 합 구하기, C++) [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-2042%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-c-baekjoon/36648/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2636번 (치즈, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2636%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/36604/</link>
					<comments>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2636%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/36604/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 26 Aug 2023 02:52:29 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2636]]></category>
		<category><![CDATA[2636번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Gold]]></category>
		<category><![CDATA[Gold4]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[골드]]></category>
		<category><![CDATA[골드4]]></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[백준]]></category>
		<category><![CDATA[백준 2636]]></category>
		<category><![CDATA[백준 2636번]]></category>
		<category><![CDATA[시뮬레이션]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[치즈]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36604</guid>

					<description><![CDATA[<p>백준 2636번 '치즈' 문제에 대한 글입니다. BFS 알고리즘을 이용하여 해결하였습니다.(This article is about the question of "Cheese" in Baekjoon Number 2636. It was solved using the BFS algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2636%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/36604/">백준 2636번 (치즈, C++) [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>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-75779d84      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#치즈" class="uagb-toc-link__trigger">치즈</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">치즈 <img decoding="async" width="30" height="38" class="wp-image-37904" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Gold_4.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Gold_4.jpg 400w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_4-234x300.jpg 234w" sizes="(max-width: 30px) 100vw, 30px" /></h1>



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



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



<figure 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">1 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">25672</td><td class="has-text-align-left" data-align="left">14240</td><td class="has-text-align-left" data-align="left">10335</td><td class="has-text-align-left" data-align="left">54.602%</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p class="wp-block-paragraph">아래 &lt;그림 1&gt;과 같이 정사각형 칸들로 이루어진 사각형 모양의 판이 있고, </p>



<p class="wp-block-paragraph">그 위에 얇은 치즈(회색으로 표시된 부분)가 놓여 있다. </p>



<p class="wp-block-paragraph">판의 가장자리(&lt;그림 1&gt;에서 네모 칸에 X친 부분)에는 치즈가 놓여 있지 않으며 치즈에는 하나 이상의 구멍이 있을 수 있다.</p>



<p class="wp-block-paragraph">이 치즈를 공기 중에 놓으면 녹게 되는데 공기와 접촉된 칸은 한 시간이 지나면 녹아 없어진다. </p>



<p class="wp-block-paragraph">치즈의 구멍 속에는 공기가 없지만 구멍을 둘러싼 치즈가 녹아서 구멍이 열리면 구멍 속으로 공기가 들어가게 된다. </p>



<p class="wp-block-paragraph">&lt;그림 1&gt;의 경우, 치즈의 구멍을 둘러싼 치즈는 녹지 않고 ‘c’로 표시된 부분만 한 시간 후에 녹아 없어져서 &lt;그림 2&gt;와 같이 된다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="379" height="408" src="https://lycos7560.com/wp-content/uploads/2023/08/image-25.png" alt="" class="wp-image-36609" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-25.png 379w, https://lycos7560.com/wp-content/uploads/2023/08/image-25-279x300.png 279w" sizes="(max-width: 379px) 100vw, 379px" /></figure>



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



<p class="wp-block-paragraph">다시 한 시간 후에는 &lt;그림 2&gt;에서 ‘c’로 표시된 부분이 녹아 없어져서 &lt;그림 3&gt;과 같이 된다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="371" height="860" src="https://lycos7560.com/wp-content/uploads/2023/08/image-26.png" alt="" class="wp-image-36610" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-26.png 371w, https://lycos7560.com/wp-content/uploads/2023/08/image-26-129x300.png 129w" sizes="(max-width: 371px) 100vw, 371px" /></figure>



<p class="wp-block-paragraph">&lt;그림 3&gt;은 원래 치즈의 두 시간 후 모양을 나타내고 있으며, </p>



<p class="wp-block-paragraph">남은 조각들은 한 시간이 더 지나면 모두&nbsp;녹아 없어진다. </p>



<p class="wp-block-paragraph">그러므로 처음 치즈가 모두 녹아 없어지는 데는 세 시간이 걸린다. </p>



<p class="wp-block-paragraph">&lt;그림 3&gt;과 같이 치즈가 녹는 과정에서 여러 조각으로 나누어 질 수도 있다.</p>



<p class="wp-block-paragraph">입력으로 사각형 모양의 판의 크기와 한 조각의 치즈가 판 위에 주어졌을 때, </p>



<p class="wp-block-paragraph"><strong>공기 중에서 치즈가 모두 녹아 없어지는 데 걸리는 시간과 </strong></p>



<p class="wp-block-paragraph"><strong>모두 녹기 한 시간 전에 남아있는 치즈조각이 놓여 있는 칸의 개수를 구하는 프로그램을 작성하시오.</strong></p>



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



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p class="wp-block-paragraph">첫째 줄에는 사각형 모양 판의 세로와 가로의 길이가 양의 정수로 주어진다. </p>



<p class="wp-block-paragraph">세로와 가로의 길이는 최대 100이다. </p>



<p class="wp-block-paragraph">판의 각 가로줄의 모양이 윗 줄부터 차례로 둘째 줄부터 마지막 줄까지 주어진다. </p>



<p class="wp-block-paragraph">치즈가 없는 칸은 0, 치즈가 있는 칸은 1로 주어지며 각 숫자 사이에는 빈칸이 하나씩 있다.</p>



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



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p class="wp-block-paragraph">첫째 줄에는 치즈가 모두 녹아서 없어지는 데 걸리는 시간을 출력하고, </p>



<p class="wp-block-paragraph">둘째 줄에는 모두 녹기 한 시간 전에 남아있는 치즈조각이 놓여 있는 칸의 개수를 출력한다.</p>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<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="">13 12
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 0 0 0
0 1 1 1 0 0 0 1 1 0 0 0
0 1 1 1 1 1 1 0 0 0 0 0
0 1 1 1 1 1 0 1 1 0 0 0
0 1 1 1 1 0 0 1 1 0 0 0
0 0 1 1 0 0 0 1 1 0 0 0
0 0 1 1 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<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="">3
5</pre>



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



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<p class="wp-block-paragraph"><a href="https://www.acmicpc.net/category/2">Olympiad</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/55">한국정보올림피아드</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/78">KOI 2000</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/391">초등부</a>&nbsp;3번</p>



<ul class="wp-block-list">
<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/compro0317">compro0317</a>,&nbsp;<a href="https://www.acmicpc.net/user/shawn050912">shawn050912</a></li>



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/jung2381187">jung2381187</a></li>
</ul>



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



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/102">구현</a></li>



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



<li><a href="https://www.acmicpc.net/problem/tag/11">그래프 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/141">시뮬레이션</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/126">너비 우선 탐색</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)"/>



<h2 class="wp-block-heading has-large-font-size">통과된 코드</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;queue>
#include &lt;vector>
using namespace std;
constexpr short MAX = 100;
short _N, _M, _Cheese = 0;
short _DxDy[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };
bool _Map[MAX][MAX];
bool _IsVisted[MAX][MAX];
vector&lt;short> Records;
vector&lt;pair&lt;short, short>> _Next;
queue&lt;pair&lt;short, short>> BFSqueue;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _N >> _M;
	bool _t;
	for (short i = 0; i &lt; _N; i++)
		for (short j = 0; j &lt; _M; j++) {
			cin >> _t;
			_Map[i][j] = _t;
			if (_t == 1)
				_Cheese++;
		}
	short _time = 0;
	while (true) {
		Records.push_back(_Cheese);
		if (_Cheese == 0)
			break;
		for (short i = 0; i &lt; _N; i++)
			for (short j = 0; j &lt; _M; j++)
				_IsVisted[i][j] = false;
		_Next.clear();
		BFSqueue.push({ 0,0 });
		_IsVisted[0][0] = true;
		while (!BFSqueue.empty()) {
			pair&lt;short, short> _pos = BFSqueue.front();
			BFSqueue.pop();
			for (short i = 0; i &lt; 4; i++) {
				short _dx = _pos.first + _DxDy[i][0];
				short _dy = _pos.second + _DxDy[i][1];

				if (_dx &lt; 0 || _dy &lt; 0 || _dx >= _N || _dy >= _M)
					continue;
				if (_IsVisted[_dx][_dy])
					continue;
				if (_Map[_dx][_dy] == 1) {
					_Next.push_back({ _dx, _dy });
					_IsVisted[_dx][_dy] = true;
					continue;
				}

				_IsVisted[_dx][_dy] = true;
				BFSqueue.push({ _dx, _dy});
			}
		}

		for (auto&amp; it : _Next) {
			_Map[it.first][it.second] = 0;
			_Cheese--;
		}

		_time++;
	}

	cout &lt;&lt; _time &lt;&lt; "\n" &lt;&lt; Records[Records.size() - 2];


	return 0;
}</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="1063" height="86" src="https://lycos7560.com/wp-content/uploads/2023/08/image-24.png" alt="" class="wp-image-36605" style="aspect-ratio:12.28;width:1045px;height:auto" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-24.png 1063w, https://lycos7560.com/wp-content/uploads/2023/08/image-24-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-24-768x62.png 768w" sizes="(max-width: 1063px) 100vw, 1063px" /></figure>



<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="4386247858"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2636%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/36604/">백준 2636번 (치즈, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-2636%eb%b2%88-%ec%b9%98%ec%a6%88-c-baekjoon/36604/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2573번 (빙산, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2573%eb%b2%88-%eb%b9%99%ec%82%b0-c-baekjoon/36585/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2573%eb%b2%88-%eb%b9%99%ec%82%b0-c-baekjoon/36585/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 25 Aug 2023 16:57:28 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2573]]></category>
		<category><![CDATA[2573번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Gold]]></category>
		<category><![CDATA[Gold4]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[골드]]></category>
		<category><![CDATA[골드4]]></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[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2573]]></category>
		<category><![CDATA[백준 2573번]]></category>
		<category><![CDATA[빙산]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36585</guid>

					<description><![CDATA[<p>백준 2573번 '빙산' 문제에 대한 글입니다. BFS 알고리즘을 이용하여 해결하였습니다. (This article is about the issue of "ice mountain" in Baekjoon Number 2573. It was solved using the BFS algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2573%eb%b2%88-%eb%b9%99%ec%82%b0-c-baekjoon/36585/">백준 2573번 (빙산, C++) [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>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-75779d84      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#빙산" class="uagb-toc-link__trigger">빙산</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">빙산 <img decoding="async" width="30" height="38" class="wp-image-37904" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Gold_4.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Gold_4.jpg 400w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_4-234x300.jpg 234w" sizes="(max-width: 30px) 100vw, 30px" /></h1>



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



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



<figure 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">1 초</td><td class="has-text-align-left" data-align="left">256 MB</td><td class="has-text-align-left" data-align="left">66795</td><td class="has-text-align-left" data-align="left">18943</td><td class="has-text-align-left" data-align="left">12600</td><td class="has-text-align-left" data-align="left">25.842%</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p class="wp-block-paragraph">지구 온난화로 인하여 북극의 빙산이 녹고 있다. </p>



<p class="wp-block-paragraph">빙산을 그림 1과 같이 2차원 배열에 표시한다고 하자. </p>



<p class="wp-block-paragraph">빙산의 각 부분별 높이 정보는 배열의 각 칸에 양의 정수로 저장된다. </p>



<p class="wp-block-paragraph">빙산 이외의 바다에 해당되는 칸에는 0이 저장된다. </p>



<p class="wp-block-paragraph">그림 1에서 빈칸은 모두 0으로 채워져 있다고 생각한다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="598" height="362" src="https://lycos7560.com/wp-content/uploads/2023/08/image-22.png" alt="" class="wp-image-36590" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-22.png 598w, https://lycos7560.com/wp-content/uploads/2023/08/image-22-300x182.png 300w" sizes="(max-width: 598px) 100vw, 598px" /><figcaption class="wp-element-caption">그림 1. 행의 개수가 5이고 열의 개수가 7인 2차원 배열에 저장된 빙산의 높이 정보</figcaption></figure>



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



<p class="wp-block-paragraph">빙산의 높이는 바닷물에 많이 접해있는 부분에서 더 빨리 줄어들기 때문에, </p>



<p class="wp-block-paragraph">배열에서 빙산의 각 부분에 해당되는 칸에 있는 높이는 일년마다 그 칸에 동서남북 네 방향으로 붙어있는 0이 저장된 칸의 개수만큼 줄어든다. </p>



<p class="wp-block-paragraph">단, 각 칸에 저장된 높이는 0보다 더 줄어들지 않는다. </p>



<p class="wp-block-paragraph">바닷물은 호수처럼 빙산에 둘러싸여 있을 수도 있다. </p>



<p class="wp-block-paragraph">따라서 그림 1의 빙산은 일년후에 그림 2와 같이 변형된다.</p>



<p class="wp-block-paragraph">그림 3은 그림 1의 빙산이 2년 후에 변한 모습을 보여준다. </p>



<p class="wp-block-paragraph">2차원 배열에서 동서남북 방향으로 붙어있는 칸들은 서로 연결되어 있다고 말한다. </p>



<p class="wp-block-paragraph">따라서 그림 2의 빙산은 한 덩어리이지만, 그림 3의 빙산은 세 덩어리로 분리되어 있다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="636" height="900" src="https://lycos7560.com/wp-content/uploads/2023/08/image-23.png" alt="" class="wp-image-36593" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-23.png 636w, https://lycos7560.com/wp-content/uploads/2023/08/image-23-212x300.png 212w" sizes="(max-width: 636px) 100vw, 636px" /></figure>



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



<p class="wp-block-paragraph">한 덩어리의 빙산이 주어질 때, 이 빙산이 두 덩어리 이상으로 분리되는 최초의 시간(년)을 구하는 프로그램을 작성하시오. </p>



<p class="wp-block-paragraph">그림 1의 빙산에 대해서는 2가 답이다. </p>



<p class="wp-block-paragraph">만일 전부 다 녹을 때까지 두 덩어리 이상으로 분리되지 않으면 프로그램은 0을 출력한다.</p>



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



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p class="wp-block-paragraph">첫 줄에는 이차원 배열의 행의 개수와 열의 개수를 나타내는 두 정수 N과 M이 한 개의 빈칸을 사이에 두고 주어진다. </p>



<p class="wp-block-paragraph">N과 M은 3 이상 300 이하이다. 그 다음 N개의 줄에는 각 줄마다 배열의 각 행을 나타내는 M개의 정수가 한 개의 빈 칸을 사이에 두고 주어진다. </p>



<p class="wp-block-paragraph">각 칸에 들어가는 값은 0 이상 10 이하이다. </p>



<p class="wp-block-paragraph">배열에서 빙산이 차지하는 칸의 개수, 즉, 1 이상의 정수가 들어가는 칸의 개수는 10,000 개 이하이다. </p>



<p class="wp-block-paragraph">배열의 첫 번째 행과 열, 마지막 행과 열에는 항상 0으로 채워진다.</p>



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



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p class="wp-block-paragraph">첫 줄에 빙산이 분리되는 최초의 시간(년)을 출력한다. </p>



<p class="wp-block-paragraph">만일 빙산이 다 녹을 때까지 분리되지 않으면 0을 출력한다.</p>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<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 7
0 0 0 0 0 0 0
0 2 4 5 3 0 0
0 3 0 2 5 2 0
0 7 6 2 4 0 0
0 0 0 0 0 0 0</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<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</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 A</h3>



<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 7
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 0 0 0 0 
0 0 0 0 0 0 0
0 0 0 0 0 0 0</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 A</h3>



<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="">0</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 B</h3>



<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="">7 7
0 0 0 0 0 0 0
0 1 1 0 1 1 0
0 1 9 1 9 1 0
0 1 1 1 1 1 0
0 1 1 1 1 1 0
0 0 1 1 1 0 0
0 0 0 0 0 0 0</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 B</h3>



<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</pre>



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



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<p class="wp-block-paragraph"><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/55" target="_blank" rel="noreferrer noopener">한국정보올림피아드</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/69" target="_blank" rel="noreferrer noopener">KOI 2006</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/364">초등부</a>&nbsp;2번</p>



<ul class="wp-block-list">
<li>잘못된 데이터를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/occidere" target="_blank" rel="noreferrer noopener">occidere</a>,&nbsp;<a href="https://www.acmicpc.net/user/zayne" target="_blank" rel="noreferrer noopener">zayne</a></li>
</ul>



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



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/102">구현</a></li>



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



<li><a href="https://www.acmicpc.net/problem/tag/11">그래프 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/126">너비 우선 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/127">깊이 우선 탐색</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)"/>



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



<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;queue>
using namespace std;
constexpr short MAX = 300;
short _MAP[2][MAX][MAX];
bool _IsVisted[MAX][MAX];
short _N, _M, _Res = 0, _Glaciers = 0, _Cluster = 0;
short _DxDy[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

void BFS(short _i, short _j)
{
	queue&lt;pair&lt;short, short>> BFSQueue;
	BFSQueue.push({ _i, _j });
	while (!BFSQueue.empty()) {
		pair&lt;short, short> _CntPos = BFSQueue.front();
		BFSQueue.pop();
		short _Sea = 0;
		for (short i = 0; i &lt; 4; i++) {
			short _dx = _CntPos.first + _DxDy[i][0];
			short _dy = _CntPos.second + _DxDy[i][1];
			if (_dx &lt; 0 || _dy &lt; 0 || _dx >= _N || _dy >= _M)
				continue;
			if (_MAP[0][_dx][_dy] &lt;= 0) {
				_Sea++;
				continue;
			}
			if (_IsVisted[_dx][_dy])
				continue;
			_IsVisted[_dx][_dy] = true;
			BFSQueue.push({ _dx, _dy });
		}
		_MAP[1][_CntPos.first][_CntPos.second] = _Sea;
	}
}


short ClusterCount()
{
	short _cnt = 0;
	for (short i = 0; i &lt; _N; i++)
		for (short j = 0; j &lt; _M; j++)
			_IsVisted[i][j] = false;
	for (short i = 0; i &lt; _N; i++)
		for (short j = 0; j &lt; _M; j++) {
			if (_MAP[0][i][j] &lt;= 0 || _IsVisted[i][j])
				continue;
			BFS(i, j);
			_cnt++;
		}
	return _cnt;
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _N >> _M;
	short _Temp;
	for (short i = 0; i &lt; _N; i++)
		for (short j = 0; j &lt; _M; j++) {
			cin >> _Temp;
			if (_Temp > 0)
				_Glaciers++;
			_MAP[0][i][j] = _Temp;
		}
	short _Cnt = 0;
	while (true) {
		_Cluster = ClusterCount();
		if (_Cluster >= 2 ) {
			_Res = _Cnt;
			break;
		}
		if (_Glaciers &lt;= 1) {
			_Res = 0; 
			break;
		}

		for (short i = 0; i &lt; _N; i++)
			for (short j = 0; j &lt; _M; j++) {
				if (_MAP[0][i][j] &lt;= 0)
					continue;
				_MAP[0][i][j] -= _MAP[1][i][j];
				if (_MAP[0][i][j] &lt;= 0)
					_Glaciers--;
			}
		_Cnt++;
	}

	cout &lt;&lt; _Res;

	return 0;
}</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="1205" height="190" src="https://lycos7560.com/wp-content/uploads/2023/08/image-21.png" alt="" class="wp-image-36587" style="width:867px;height:137px" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-21.png 1205w, https://lycos7560.com/wp-content/uploads/2023/08/image-21-300x47.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-21-768x121.png 768w" sizes="(max-width: 1205px) 100vw, 1205px" /></figure>



<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="4386247858"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2573%eb%b2%88-%eb%b9%99%ec%82%b0-c-baekjoon/36585/">백준 2573번 (빙산, C++) [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-2573%eb%b2%88-%eb%b9%99%ec%82%b0-c-baekjoon/36585/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 5639번 (이진 검색 트리, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-5639%eb%b2%88-%ec%9d%b4%ec%a7%84-%ea%b2%80%ec%83%89-%ed%8a%b8%eb%a6%ac-c-baekjoon/36556/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-5639%eb%b2%88-%ec%9d%b4%ec%a7%84-%ea%b2%80%ec%83%89-%ed%8a%b8%eb%a6%ac-c-baekjoon/36556/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 23 Aug 2023 04:20:19 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[5639]]></category>
		<category><![CDATA[5639번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[endoffile]]></category>
		<category><![CDATA[EOF]]></category>
		<category><![CDATA[Gold]]></category>
		<category><![CDATA[Gold5]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[골드]]></category>
		<category><![CDATA[골드5]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 5639]]></category>
		<category><![CDATA[백준 5639번]]></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=36556</guid>

					<description><![CDATA[<p>백준 온라인 저지 5639번 문제 '이진 검색 트리' 에 대한 글입니다. 단순한 재귀를 이용하여 해결하였습니다. (Baekjoon Online Judge Number 5639 This article is about the binary search tree. It was solved using simple recursion.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-5639%eb%b2%88-%ec%9d%b4%ec%a7%84-%ea%b2%80%ec%83%89-%ed%8a%b8%eb%a6%ac-c-baekjoon/36556/">백준 5639번 (이진 검색 트리, C++) [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>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-75779d84      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#이진-검색-트리" class="uagb-toc-link__trigger">이진 검색 트리</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">이진 검색 트리 <img decoding="async" width="30" height="38" class="wp-image-37922" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-1.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-1.jpg 1250w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-1-234x300.jpg 234w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-1-768x983.jpg 768w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_5-1-1200x1536.jpg 1200w" sizes="(max-width: 30px) 100vw, 30px" /></h1>



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



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



<figure 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">1 초</td><td class="has-text-align-left" data-align="left">256 MB</td><td class="has-text-align-left" data-align="left">35442</td><td class="has-text-align-left" data-align="left">13888</td><td class="has-text-align-left" data-align="left">9821</td><td class="has-text-align-left" data-align="left">38.260%</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p class="wp-block-paragraph">이진 검색 트리는 다음과 같은 세 가지 조건을 만족하는 이진 트리이다.</p>



<ul class="wp-block-list">
<li>노드의 왼쪽 서브트리에 있는 모든 노드의 키는 노드의 키보다 작다.</li>



<li>노드의 오른쪽 서브트리에 있는 모든 노드의 키는 노드의 키보다 크다.</li>



<li>왼쪽, 오른쪽 서브트리도 이진 검색 트리이다.</li>
</ul>



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



<figure class="wp-block-image size-full"><img decoding="async" width="677" height="315" src="https://lycos7560.com/wp-content/uploads/2023/08/image-17.png" alt="" class="wp-image-36557" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-17.png 677w, https://lycos7560.com/wp-content/uploads/2023/08/image-17-300x140.png 300w" sizes="(max-width: 677px) 100vw, 677px" /></figure>



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



<p class="wp-block-paragraph">전위 순회 (루트-왼쪽-오른쪽)은 루트를 방문하고, 왼쪽 서브트리, 오른쪽 서브 트리를 순서대로 방문하면서 노드의 키를 출력한다. </p>



<p class="wp-block-paragraph">후위 순회 (왼쪽-오른쪽-루트)는 왼쪽 서브트리, 오른쪽 서브트리, 루트 노드 순서대로 키를 출력한다. </p>



<p class="wp-block-paragraph">예를 들어, 위의 이진 검색 트리의 전위 순회 결과는 50 30 24 5 28 45 98 52 60 이고, 후위 순회 결과는 5 28 24 45 30 60 52 98 50 이다.</p>



<p class="wp-block-paragraph">이진 검색 트리를 전위 순회한 결과가 주어졌을 때, 이 트리를 후위 순회한 결과를 구하는 프로그램을 작성하시오.</p>



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



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p class="wp-block-paragraph">트리를 전위 순회한 결과가 주어진다. </p>



<p class="wp-block-paragraph">노드에 들어있는 키의 값은 10<sup>6</sup>보다 작은 양의 정수이다. </p>



<p class="wp-block-paragraph">모든 값은 한 줄에 하나씩 주어지며, 노드의 수는 10,000개 이하이다. </p>



<p class="wp-block-paragraph">같은 키를 가지는 노드는 없다.</p>



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



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p class="wp-block-paragraph">입력으로 주어진 이진 검색 트리를 후위 순회한 결과를 한 줄에 하나씩 출력한다.</p>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<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="">50
30
24
5
28
45
98
52
60</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<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
28
24
45
30
60
52
98
50</pre>



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



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<p class="wp-block-paragraph"><a href="https://www.acmicpc.net/category/1" target="_blank" rel="noreferrer noopener">ICPC</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/7" target="_blank" rel="noreferrer noopener">Regionals</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/42" target="_blank" rel="noreferrer noopener">Asia Pacific</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/102" target="_blank" rel="noreferrer noopener">Thailand</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/562" target="_blank" rel="noreferrer noopener">2011 ACM-ICPC Asia Phuket Regional Programming Contest</a>&nbsp;B번</p>



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



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



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<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/11" target="_blank" rel="noreferrer noopener">그래프 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/120" target="_blank" rel="noreferrer noopener">트리</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/62" 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)"/>



<h2 class="wp-block-heading has-large-font-size">통과된 코드</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>

using namespace std;

struct BinaryNode
{
    int _Num;
    BinaryNode* _Left;
    BinaryNode* _Right;

    BinaryNode(int num)
        : _Num(num), _Left(nullptr), _Right(nullptr)
    {}

    void ArrayBinaryNode(int _n)
    {
        if (_Num > _n) {
            if (_Left == nullptr) _Left = new BinaryNode(_n);
            else _Left->ArrayBinaryNode(_n);
        }
        else {
            if (_Right == nullptr) _Right = new BinaryNode(_n);
            else _Right->ArrayBinaryNode(_n);
        }
    }
};

void PostorderTraverse(BinaryNode&amp; CurrentNode)
{
    if (CurrentNode._Left != nullptr) PostorderTraverse(*CurrentNode._Left);
    if (CurrentNode._Right != nullptr) PostorderTraverse(*CurrentNode._Right);
    cout &lt;&lt; CurrentNode._Num &lt;&lt; "\n";
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int _N;
    cin >> _N;
    BinaryNode _RootNode(_N);
    while (true) {
        cin >> _N;
        if (cin.eof() == true)
            break;
        _RootNode.ArrayBinaryNode(_N);
    }

    PostorderTraverse(_RootNode);

	return 0;
}

</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="1076" height="98" src="https://lycos7560.com/wp-content/uploads/2023/08/image-18.png" alt="" class="wp-image-36561" style="width:927px;height:84px" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-18.png 1076w, https://lycos7560.com/wp-content/uploads/2023/08/image-18-300x27.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-18-768x70.png 768w" sizes="(max-width: 1076px) 100vw, 1076px" /></figure>



<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="4386247858"></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-5639%eb%b2%88-%ec%9d%b4%ec%a7%84-%ea%b2%80%ec%83%89-%ed%8a%b8%eb%a6%ac-c-baekjoon/36556/">백준 5639번 (이진 검색 트리, C++) [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-5639%eb%b2%88-%ec%9d%b4%ec%a7%84-%ea%b2%80%ec%83%89-%ed%8a%b8%eb%a6%ac-c-baekjoon/36556/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1967번 (트리의 지름, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1967%eb%b2%88-%ed%8a%b8%eb%a6%ac%ec%9d%98-%ec%a7%80%eb%a6%84-c-baekjoon/36529/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1967%eb%b2%88-%ed%8a%b8%eb%a6%ac%ec%9d%98-%ec%a7%80%eb%a6%84-c-baekjoon/36529/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 17 Aug 2023 00:01:03 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1967]]></category>
		<category><![CDATA[1967번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[dfs]]></category>
		<category><![CDATA[Gold]]></category>
		<category><![CDATA[Gold4]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[골드]]></category>
		<category><![CDATA[골드4]]></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[백준 1967]]></category>
		<category><![CDATA[백준 1967번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[트리]]></category>
		<category><![CDATA[트리의 지름]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36529</guid>

					<description><![CDATA[<p>백준 1967번 '트리의 지름' 문제에 대한 글입니다. DFS 탐색 알고리즘을 이용하여 해결하였습니다. (This article is about the problem of Baekjoon Number 1967 'Diameter of the Tree'. It was solved using the DFS search algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1967%eb%b2%88-%ed%8a%b8%eb%a6%ac%ec%9d%98-%ec%a7%80%eb%a6%84-c-baekjoon/36529/">백준 1967번 (트리의 지름, C++) [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>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-75779d84      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#트리의-지름" class="uagb-toc-link__trigger">트리의 지름</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">트리의 지름 <img decoding="async" width="30" height="38" class="wp-image-37904" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Gold_4.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Gold_4.jpg 400w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_4-234x300.jpg 234w" sizes="(max-width: 30px) 100vw, 30px" /></h1>



<p class="wp-block-paragraph"><a href="https://www.acmicpc.net/problem/1967">https://www.acmicpc.net/problem/1967</a></p>



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



<figure 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">39735</td><td class="has-text-align-left" data-align="left">15747</td><td class="has-text-align-left" data-align="left">11924</td><td class="has-text-align-left" data-align="left">41.200%</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p class="wp-block-paragraph">트리(tree)는 사이클이 없는 무방향 그래프이다. </p>



<p class="wp-block-paragraph">트리에서는 어떤 두 노드를 선택해도 둘 사이에 경로가 항상 하나만 존재하게 된다. </p>



<p class="wp-block-paragraph">트리에서 어떤 두 노드를 선택해서 양쪽으로 쫙 당길 때, 가장 길게 늘어나는 경우가 있을 것이다. </p>



<p class="wp-block-paragraph">이럴 때 트리의 모든 노드들은 이 두 노드를 지름의 끝 점으로 하는 원 안에 들어가게 된다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="483" height="201" src="https://lycos7560.com/wp-content/uploads/2023/08/image-12.png" alt="" class="wp-image-36531" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-12.png 483w, https://lycos7560.com/wp-content/uploads/2023/08/image-12-300x125.png 300w" sizes="(max-width: 483px) 100vw, 483px" /></figure>



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



<p class="wp-block-paragraph">이런 두 노드 사이의 경로의 길이를 트리의 지름이라고 한다. </p>



<p class="wp-block-paragraph">정확히 정의하자면 트리에 존재하는 모든 경로들 중에서 가장 긴 것의 길이를 말한다.</p>



<p class="wp-block-paragraph">입력으로 루트가 있는 트리를 가중치가 있는 간선들로 줄 때, 트리의 지름을 구해서 출력하는 프로그램을 작성하시오. </p>



<p class="wp-block-paragraph">아래와 같은 트리가 주어진다면 트리의 지름은 45가 된다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="486" height="262" src="https://lycos7560.com/wp-content/uploads/2023/08/image-14.png" alt="" class="wp-image-36533" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-14.png 486w, https://lycos7560.com/wp-content/uploads/2023/08/image-14-300x162.png 300w" sizes="(max-width: 486px) 100vw, 486px" /></figure>



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



<p class="wp-block-paragraph">트리의 노드는 1부터 n까지 번호가 매겨져 있다.</p>



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



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p class="wp-block-paragraph">파일의 첫 번째 줄은 노드의 개수 n(1 ≤ n ≤ 10,000)이다. </p>



<p class="wp-block-paragraph">둘째 줄부터 n-1개의 줄에 각 간선에 대한 정보가 들어온다. </p>



<p class="wp-block-paragraph">간선에 대한 정보는 세 개의 정수로 이루어져 있다. </p>



<p class="wp-block-paragraph">첫 번째 정수는 간선이 연결하는 두 노드 중 부모 노드의 번호를 나타내고, 두 번째 정수는 자식 노드를, 세 번째 정수는 간선의 가중치를 나타낸다. </p>



<p class="wp-block-paragraph">간선에 대한 정보는 부모 노드의 번호가 작은 것이 먼저 입력되고, 부모 노드의 번호가 같으면 자식 노드의 번호가 작은 것이 먼저 입력된다. </p>



<p class="wp-block-paragraph">루트 노드의 번호는 항상 1이라고 가정하며, 간선의 가중치는 100보다 크지 않은 양의 정수이다.</p>



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



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p class="wp-block-paragraph">첫째 줄에 트리의 지름을 출력한다.</p>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<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="">12
1 2 3
1 3 2
2 4 5
3 5 11
3 6 9
4 7 1
4 8 7
5 9 15
5 10 4
6 11 6
6 12 10</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<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="">45</pre>



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



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<ul class="wp-block-list">
<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/apjw6112">apjw6112</a></li>



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/dlwjsgud12">dlwjsgud12</a>,&nbsp;<a href="https://www.acmicpc.net/user/shg9411" target="_blank" rel="noreferrer noopener">shg9411</a>,&nbsp;<a href="https://www.acmicpc.net/user/tony9402" target="_blank" rel="noreferrer noopener">tony9402</a>,&nbsp;<a href="https://www.acmicpc.net/user/yongdol503" target="_blank" rel="noreferrer noopener">yongdol503</a></li>
</ul>



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



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/7">그래프 이론</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/11">그래프 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/120">트리</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/127">깊이 우선 탐색</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)"/>



<figure class="wp-block-embed is-type-wp-embed"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="wCvZK5P8Wt"><a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1167%eb%b2%88-%ed%8a%b8%eb%a6%ac%ec%9d%98-%ec%a7%80%eb%a6%84-c-baekjoon/36474/">백준 1167번 (트리의 지름, C++) [BAEKJOON]</a></blockquote><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;백준 1167번 (트리의 지름, C++) [BAEKJOON]&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1167%eb%b2%88-%ed%8a%b8%eb%a6%ac%ec%9d%98-%ec%a7%80%eb%a6%84-c-baekjoon/36474/embed/#?secret=TGKI0WPUmP#?secret=wCvZK5P8Wt" data-secret="wCvZK5P8Wt" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



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



<p class="wp-block-paragraph">백준 1167번 문제와 비슷한 문제</p>



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



<h2 class="wp-block-heading has-large-font-size">통과된 코드</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;

unsigned short _V, _ResNode;
int _Res;
bool isvisted[100001];

struct Node
{
    unsigned short Number;
    vector&lt;pair&lt;unsigned short, unsigned short>> Connections;
    Node(unsigned short _num) : Number(_num) { };
};

vector&lt;Node> Nodes;

void DFS(unsigned short cntNode, int _dist)
{
    isvisted[cntNode] = true;
    if (Nodes[cntNode].Connections.size() == 1 &amp;&amp; _ResNode != cntNode) {
        if (_Res &lt; _dist) {
            _Res = _dist;
            _ResNode = cntNode;
        }
        return;
    }

    for (auto&amp; it : Nodes[cntNode].Connections) {
        if (isvisted[it.first])
            continue;
        DFS(it.first, _dist + it.second);
    }
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> _V;
    for (int i = 0; i &lt;= _V; i++)
        Nodes.push_back(Node(i));

    unsigned short _n1, _n2, _d;
    for (int i = 0; i &lt; _V - 1; i++) {
        cin >> _n1 >> _n2 >> _d;
        Nodes[_n1].Connections.push_back({ _n2, _d });
        Nodes[_n2].Connections.push_back({ _n1, _d });
    }

    _Res = 0;
    _ResNode = 1;
    DFS(1, 0);
    for (int i = 1; i &lt;= _V; i++)
        isvisted[i] = false;
    _Res = 0;
    DFS(_ResNode, 0);
    cout &lt;&lt; _Res;
    return 0;
}</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="1443" height="114" src="https://lycos7560.com/wp-content/uploads/2023/08/image-15.png" alt="" class="wp-image-36535" style="width:1028px;height:81px" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-15.png 1443w, https://lycos7560.com/wp-content/uploads/2023/08/image-15-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-15-768x61.png 768w" sizes="(max-width: 1443px) 100vw, 1443px" /></figure>



<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="4386247858"></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-1967%eb%b2%88-%ed%8a%b8%eb%a6%ac%ec%9d%98-%ec%a7%80%eb%a6%84-c-baekjoon/36529/">백준 1967번 (트리의 지름, C++) [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-1967%eb%b2%88-%ed%8a%b8%eb%a6%ac%ec%9d%98-%ec%a7%80%eb%a6%84-c-baekjoon/36529/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1167번 (트리의 지름, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1167%eb%b2%88-%ed%8a%b8%eb%a6%ac%ec%9d%98-%ec%a7%80%eb%a6%84-c-baekjoon/36474/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1167%eb%b2%88-%ed%8a%b8%eb%a6%ac%ec%9d%98-%ec%a7%80%eb%a6%84-c-baekjoon/36474/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 12 Aug 2023 19:20:07 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1167]]></category>
		<category><![CDATA[1167번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[dfs]]></category>
		<category><![CDATA[Gold]]></category>
		<category><![CDATA[Gold2]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[골드]]></category>
		<category><![CDATA[골드2]]></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[백준 1167]]></category>
		<category><![CDATA[백준 1167번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[트리]]></category>
		<category><![CDATA[트리의 지름]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36474</guid>

					<description><![CDATA[<p>백준 1167번 '트리의 지름' 문제에 대한 글입니다. DFS를 이용하여 문제를 해결하였습니다. (This article is about Baekjoon Number 1167 'Diameter of the Tree'. I solved the problem using 'DFS')</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1167%eb%b2%88-%ed%8a%b8%eb%a6%ac%ec%9d%98-%ec%a7%80%eb%a6%84-c-baekjoon/36474/">백준 1167번 (트리의 지름, C++) [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>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-a1d67416      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#트리의-지름" class="uagb-toc-link__trigger">트리의 지름</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">트리의 지름 <img decoding="async" width="30" height="38" class="wp-image-37903" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Gold_2.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Gold_2.jpg 400w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_2-234x300.jpg 234w" sizes="(max-width: 30px) 100vw, 30px" /></h1>



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



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



<figure 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">256 MB</td><td class="has-text-align-left" data-align="left">44657</td><td class="has-text-align-left" data-align="left">16318</td><td class="has-text-align-left" data-align="left">11729</td><td class="has-text-align-left" data-align="left">33.983%</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p class="wp-block-paragraph">트리의 지름이란, 트리에서 임의의 두 점 사이의 거리 중 가장 긴 것을 말한다. </p>



<p class="wp-block-paragraph">트리의 지름을 구하는 프로그램을 작성하시오.</p>



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



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p class="wp-block-paragraph">트리가 입력으로 주어진다.</p>



<p class="wp-block-paragraph">먼저 첫 번째 줄에서는 트리의 정점의 개수 V가 주어지고 (2 ≤ V ≤ 100,000)</p>



<p class="wp-block-paragraph">둘째 줄부터 V개의 줄에 걸쳐 간선의 정보가 다음과 같이 주어진다. </p>



<p class="wp-block-paragraph">정점 번호는 1부터 V까지 매겨져 있다.</p>



<p class="wp-block-paragraph">먼저 정점 번호가 주어지고, 이어서 연결된 간선의 정보를 의미하는 정수가 두 개씩 주어지는데, </p>



<p class="wp-block-paragraph">하나는 정점번호, 다른 하나는 그 정점까지의 거리이다. </p>



<p class="wp-block-paragraph">예를 들어 네 번째 줄의 경우 정점 3은 정점 1과 거리가 2인 간선으로 연결되어 있고, </p>



<p class="wp-block-paragraph">정점 4와는 거리가 3인 간선으로 연결되어 있는 것을 보여준다. 각 줄의 마지막에는 -1이 입력으로 주어진다. </p>



<p class="wp-block-paragraph">주어지는 거리는 모두 10,000 이하의 자연수이다.</p>



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



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p class="wp-block-paragraph">첫째 줄에 트리의 지름을 출력한다.</p>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<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
1 3 2 -1
2 4 4 -1
3 1 2 4 3 -1
4 2 4 3 3 5 6 -1
5 4 6 -1</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<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="">11</pre>



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



<h3 class="wp-block-heading has-large-font-size">출처</h3>



<ul class="wp-block-list">
<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/ababc1005" target="_blank" rel="noreferrer noopener">ababc1005</a>, <a href="https://www.acmicpc.net/user/cfghj101" target="_blank" rel="noreferrer noopener">cfghj101</a>, <a href="https://www.acmicpc.net/user/WeissBlume" target="_blank" rel="noreferrer noopener">WeissBlume</a></li>



<li>문제를 만든 사람: <a href="https://www.acmicpc.net/user/author5" target="_blank" rel="noreferrer noopener">author5</a></li>



<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/djm03178" target="_blank" rel="noreferrer noopener">djm03178</a></li>
</ul>



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



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<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/11" target="_blank" rel="noreferrer noopener">그래프 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/120" target="_blank" rel="noreferrer noopener">트리</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/127" target="_blank" rel="noreferrer noopener">깊이 우선 탐색</a></li>
</ul>



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



<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)"/>



<h2 class="wp-block-heading has-large-font-size">통과된 코드</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;

int _V,  _ResNode, _Res;
bool isvisted[100001];

struct Node
{
	int Number;
	vector&lt;pair&lt;int, int>> Connections;
	Node(int _num) : Number(_num) { };
};

vector&lt;Node> Nodes;

void DFS(int cntNode, int _dist) 
{
	isvisted[cntNode] = true;
	if (Nodes[cntNode].Connections.size() == 1 &amp;&amp; _ResNode != cntNode) {
		if (_Res &lt; _dist) {
			_Res = _dist;
			_ResNode = cntNode;
		}
		return;
	}

	for (auto&amp; it : Nodes[cntNode].Connections) { 
		if (isvisted[it.first])
			continue;
		DFS(it.first, _dist + it.second);
	}
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _V;
	for (int i = 0; i &lt;= _V; i++) 
		Nodes.push_back(Node(i));
	
	int _n1, _n2, _d;
	for (int i = 1; i &lt;= _V; i++) {
		cin >> _n1;
		while (true) {
			cin >> _n2;
			if (_n2 == -1) break;
			cin >> _d;
			Nodes[_n1].Connections.push_back({ _n2, _d});
		}
	}

	_Res = 0;
	_ResNode = 1;
	DFS(1, 0);
	for (int i = 1; i &lt;= _V; i++)
		isvisted[i] = false;
	_Res = 0;
	DFS(_ResNode, 0);
	cout &lt;&lt; _Res;
	return 0;
}

</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="1202" height="143" src="https://lycos7560.com/wp-content/uploads/2023/08/image-5.png" alt="" class="wp-image-36480" style="width:1006px;height:120px" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-5.png 1202w, https://lycos7560.com/wp-content/uploads/2023/08/image-5-300x36.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-5-768x91.png 768w" sizes="(max-width: 1202px) 100vw, 1202px" /></figure>



<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="4386247858"></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-1167%eb%b2%88-%ed%8a%b8%eb%a6%ac%ec%9d%98-%ec%a7%80%eb%a6%84-c-baekjoon/36474/">백준 1167번 (트리의 지름, C++) [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-1167%eb%b2%88-%ed%8a%b8%eb%a6%ac%ec%9d%98-%ec%a7%80%eb%a6%84-c-baekjoon/36474/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1034번 (램프, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1034%eb%b2%88-%eb%9e%a8%ed%94%84-c-baekjoon/36454/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1034%eb%b2%88-%eb%9e%a8%ed%94%84-c-baekjoon/36454/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 11 Aug 2023 22:06:53 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1034]]></category>
		<category><![CDATA[1034번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Gold]]></category>
		<category><![CDATA[Gold4]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[골드]]></category>
		<category><![CDATA[골드4]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[램프]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1034]]></category>
		<category><![CDATA[백준 1034번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36454</guid>

					<description><![CDATA[<p>백준 1034번 '램프' 문제에 대한 글입니다. (This article is about the problem of 'Lamp' in Baekjoon Number 1034)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1034%eb%b2%88-%eb%9e%a8%ed%94%84-c-baekjoon/36454/">백준 1034번 (램프, C++) [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>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-70f244c5      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#램프" class="uagb-toc-link__trigger">램프</a></ol>					</div>
									</div>
				</div>
			


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



<h2 class="wp-block-heading">램프 <img decoding="async" width="30" height="38" class="wp-image-37904" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Gold_4.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Gold_4.jpg 400w, https://lycos7560.com/wp-content/uploads/2024/03/Gold_4-234x300.jpg 234w" sizes="(max-width: 30px) 100vw, 30px" /></h2>



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



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



<figure 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">5304</td><td class="has-text-align-left" data-align="left">2024</td><td class="has-text-align-left" data-align="left">1650</td><td class="has-text-align-left" data-align="left">41.260%</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p class="wp-block-paragraph">지민이는 각 칸마다 (1×1크기의 정사각형) 램프가 들어있는 직사각형 모양의 탁자를 샀다. </p>



<p class="wp-block-paragraph">모든 램프는 켜져있거나 꺼져있다. </p>



<p class="wp-block-paragraph">각 열의 아래에는 스위치가 하나씩 달려있는데, 이 스위치를 누를 때마다 그 열에 있는 램프의 상태가 바뀐다. </p>



<p class="wp-block-paragraph">켜져있는 램프는 꺼지고, 꺼져있는 램프는 켜진다)</p>



<p class="wp-block-paragraph">만약 어떤 행에 있는 램프가 모두 켜져있을 때, 그 행이 켜져있다고 말한다. </p>



<p class="wp-block-paragraph">지민이는 스위치를 K번 누를 것이다. 서로다른 스위치 K개를 누르지 않아도 된다. </p>



<p class="wp-block-paragraph">지민이는 스위치를 K번 눌러서 켜져있는 행을 최대로 하려고 한다.</p>



<p class="wp-block-paragraph">지민이의 탁자에 있는 램프의 상태와 K가 주어졌을 때, </p>



<p class="wp-block-paragraph">스위치를 K번 누른 후에 켜져있는 행의 최댓값을 구하는 프로그램을 작성하시오.</p>



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



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p class="wp-block-paragraph">첫째 줄에 N과 M이 주어진다. N은 행의 개수이고, M은 열의 개수이다. </p>



<p class="wp-block-paragraph">N과 M은 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에는 램프의 상태가 주어진다. </p>



<p class="wp-block-paragraph">1이 켜져있는 상태이고, 0이 꺼져있는 상태이다. </p>



<p class="wp-block-paragraph">마지막 줄에는 K가 주어진다. </p>



<p class="wp-block-paragraph">K는 1,000보다 작거나 같은 자연수 또는 0이다.</p>



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



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p class="wp-block-paragraph">첫째 줄에 문제의 정답을 출력한다.</p>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 1</h3>



<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="">3 2
01
10
10
1</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 1</h3>



<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</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 2</h3>



<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="">1 6
101010
2</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 2</h3>



<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="">0</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 3</h3>



<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 2
00
11
999</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 3</h3>



<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="">0</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 4</h3>



<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 1
0
1
0
1
0
1000</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 4</h3>



<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</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 5</h3>



<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="">14 3
001
101
001
000
111
001
101
111
110
000
111
010
110
001
6</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 5</h3>



<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="">4</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 6</h3>



<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 2
01
10
01
01
10
1</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 6</h3>



<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="">3</pre>



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



<h3 class="wp-block-heading has-large-font-size">출처</h3>



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



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



<h3 class="wp-block-heading has-large-font-size">알고리즘 분류</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/109" target="_blank" rel="noreferrer noopener">애드 혹</a></li>
</ul>



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



<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)"/>



<h3 class="wp-block-heading has-large-font-size">통과된 코드</h3>



<p class="wp-block-paragraph">재귀를 이용한 BruteForce 알고리즘을 사용하여 테이블의 램프를 제어하는 방법으로 접근했으나 시간 초과로 통과하지 못하였다.</p>



<p class="wp-block-paragraph">정답은 행에 램프가 꺼져있는 개수를 이용하여 푸는 방법</p>



<p class="wp-block-paragraph">모든 행에서 K번 안에 모두 1로 바꿀 수 있는 행을 찾고 K가 짝수 홀수 인지에 대하여 확인한다.</p>



<p class="wp-block-paragraph">만약 가능하다면 똑같은 행이 몇 개인지 확인하여 최댓값을 구한다.</p>



<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;map>
using namespace std;

int _N, _M, _K, _Res = 0;
string _Table[50];
map&lt;string, pair&lt;int, int>> CheckMap;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _N >> _M;
	for (int i = 0; i &lt; _N; i++)
		cin >> _Table[i];
	cin >> _K;

	for (int i = 0; i &lt; _N; i++) {
		int _cnt = 0;

		for (int j = 0; j &lt; _M; j++)
			if (_Table[i][j] == '0')
				_cnt++;
		if (_cnt > _K) continue;
		auto it = CheckMap.find(_Table[i]);
		if (it != CheckMap.end()) it->second.second++;
		else CheckMap.insert({ _Table[i], {_cnt, 1}});
	}

	for (auto&amp; it : CheckMap)
		if (it.second.first % 2 == _K % 2)
		   _Res = max(_Res, it.second.second);
		
	cout &lt;&lt; _Res;
	return 0;
}</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="1204" height="187" src="https://lycos7560.com/wp-content/uploads/2023/08/image-4.png" alt="" class="wp-image-36464" style="width:750px;height:116px" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-4.png 1204w, https://lycos7560.com/wp-content/uploads/2023/08/image-4-300x47.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-4-768x119.png 768w" sizes="(max-width: 1204px) 100vw, 1204px" /></figure>



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



<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="4386247858"></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-1034%eb%b2%88-%eb%9e%a8%ed%94%84-c-baekjoon/36454/">백준 1034번 (램프, C++) [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-1034%eb%b2%88-%eb%9e%a8%ed%94%84-c-baekjoon/36454/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
