<?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>백준 1260 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/%eb%b0%b1%ec%a4%80-1260/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Thu, 23 Feb 2023 00:17:32 +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>백준 1260 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 1260번 (DFS와 BFS, C++, DFS와 BFS 기본) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon-1260%eb%b2%88-dfs%ec%99%80-bfs-c-dfs%ec%99%80-bfs-%ea%b8%b0%eb%b3%b8/363/</link>
					<comments>https://lycos7560.com/cpp/baekjoon-1260%eb%b2%88-dfs%ec%99%80-bfs-c-dfs%ec%99%80-bfs-%ea%b8%b0%eb%b3%b8/363/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 27 Oct 2022 10:45:18 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1260]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[dfs]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1260]]></category>
		<category><![CDATA[백준 1260번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[예제]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.synology.me/?p=363</guid>

					<description><![CDATA[<p>DFS와 BFS https://www.acmicpc.net/problem/1260 시간 제한 메모리 제한 제출 정답 맞힌 사람 정답 비율 2 초 128 MB 208632 77192 45837 35.992% 문제 그래프를 DFS로 탐색한 결과와 BFS로 탐색한 결과를 출력하는 프로그램을 작성하시오. 단, 방문할 수 있는 정점이 여러 개인 경우에는 정점 번호가 작은 것을 먼저 방문하고, 더 이상 방문할 수 있는 점이 없는 경우 종료한다.&#160; [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon-1260%eb%b2%88-dfs%ec%99%80-bfs-c-dfs%ec%99%80-bfs-%ea%b8%b0%eb%b3%b8/363/">백준 1260번 (DFS와 BFS, C++, DFS와 BFS 기본) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="6908948342"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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



<h1 class="wp-block-heading">DFS와 BFS</h1>



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



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



<figure id="problem-info" class="wp-block-table"><table><thead><tr><th>시간 제한</th><th>메모리 제한</th><th>제출</th><th>정답</th><th>맞힌 사람</th><th>정답 비율</th></tr></thead><tbody><tr><td>2 초</td><td>128 MB</td><td>208632</td><td>77192</td><td>45837</td><td>35.992%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size wp-block-paragraph">그래프를 DFS로 탐색한 결과와 BFS로 탐색한 결과를 출력하는 프로그램을 작성하시오. </p>



<p class="has-medium-font-size wp-block-paragraph">단, 방문할 수 있는 정점이 여러 개인 경우에는 정점 번호가 작은 것을 먼저 방문하고, 더 이상 방문할 수 있는 점이 없는 경우 종료한다.&nbsp;</p>



<p class="has-medium-font-size wp-block-paragraph">정점 번호는 1번부터 N번까지이다.</p>



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



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



<p class="has-medium-font-size wp-block-paragraph">첫째 줄에 정점의 개수 N(1 ≤ N ≤ 1,000), 간선의 개수 M(1 ≤ M ≤ 10,000), 탐색을 시작할 정점의 번호 V가 주어진다. </p>



<p class="has-medium-font-size wp-block-paragraph">다음 M개의 줄에는 간선이 연결하는 두 정점의 번호가 주어진다. 어떤 두 정점 사이에 여러 개의 간선이 있을 수 있다. </p>



<p class="has-medium-font-size wp-block-paragraph">입력으로 주어지는 간선은 양방향이다.</p>



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



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



<p class="has-medium-font-size wp-block-paragraph">첫째 줄에 DFS를 수행한 결과를, 그 다음 줄에는 BFS를 수행한 결과를 출력한다. </p>



<p class="has-medium-font-size wp-block-paragraph">V부터 방문된 점을 순서대로 출력하면 된다.</p>



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



<p class="has-medium-font-size wp-block-paragraph">예제 입력 1</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 5 1
1 2
1 3
1 4
2 4
3 4</pre>



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



<p class="has-medium-font-size wp-block-paragraph">예제 출력 1</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1 2 4 3
1 2 3 4</pre>



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



<p class="has-medium-font-size wp-block-paragraph">예제 입력 2</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 5 3
5 4
5 2
1 2
3 4
3 1</pre>



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



<p class="has-medium-font-size wp-block-paragraph">예제 출력 2</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3 1 2 5 4
3 1 4 2 5</pre>



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



<p class="has-medium-font-size wp-block-paragraph">예제 입력 <strong>3</strong></p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1000 1 1000
999 1000</pre>



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



<p class="has-medium-font-size wp-block-paragraph">예제 출력 3</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1000 999
1000 999</pre>



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



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



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



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



<li>어색한 표현을 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/doju" target="_blank" rel="noreferrer noopener">doju</a></li>



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



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



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



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



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



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



<p class="has-medium-font-size wp-block-paragraph">DFS와 BFS의 기본적인 개념을 묻는 문제</p>



<div style="height:56px" 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; 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:59px" aria-hidden="true" class="wp-block-spacer"></div>



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



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



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

using namespace std;
#define MAX 1001

int N, M, V; // 정점의 개수, 간선의 개수, 시작 정점
int map[MAX][MAX]; // 인접 행렬의 그래프
bool visited[MAX]; // 정점의 방문 여부
queue&lt;int> q;

void Reset()
{
	for (int i = 0; i &lt;= N; i++)
	{
		visited[i] = 0; // 방문 초기화
	}
}

void DFS(int v)
{
	// 해당 정점 방문으로 변경
	visited[v] = true;
	cout &lt;&lt; v &lt;&lt; " ";

	for (int i = 1; i &lt;= N; i++)
	{
		// 현재 정점과 연결되어있고 방문 되지 않았으면 실행
		if (map[v][i] == 1 &amp;&amp; visited[i] == 0)
		{
			DFS(i); // 재귀
		}
 
	}

}

void BFS(int v)
{
	q.push(v); // 해당 점점 queue에 푸시
	visited[v] = true; // 해당 정점 방문으로 변경
	cout &lt;&lt; v &lt;&lt; " ";

	while(!q.empty()) // queue가 비어있지 않으면 실행
	{
		v = q.front(); // queue 제일 앞에 있는 원소를 반환
		q.pop(); // queue 제일 앞에 있는 원소를 반환

		for (int j = 1; j &lt;= N; j++)
		{
			// 현재의 정점과 연결되어 있고 방문 되지 않았으면 실행
			if (map[v][j] == 1 &amp;&amp; visited[j] == 0)
			{
				q.push(j);
				visited[j] = true;
				cout &lt;&lt; j &lt;&lt; " ";
			}
		}

	}
}


int main()
{
	cin >> N >> M >> V;

	for (int i = 0; i &lt; M; i++)
	{
		int a, b;
		cin >> a >> b;
		map[a][b] = 1;
		map[b][a] = 1;
	}


	Reset();
	DFS(V);

	cout &lt;&lt; '\n';

	Reset();
	BFS(V);

	return 0;
}</pre>



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



<p class="has-medium-font-size wp-block-paragraph">알고리즘 관련 개념이 없어서 시간을 많이 소요했다.</p>



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



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



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



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