<?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>백준 2606번 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/%EB%B0%B1%EC%A4%80-2606%EB%B2%88/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Wed, 22 Feb 2023 23:59:07 +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>백준 2606번 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 2606번 (바이러스, C++, BFS) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2606%eb%b2%88-%eb%b0%94%ec%9d%b4%eb%9f%ac%ec%8a%a4-c-bfs-baekjoon/5161/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2606%eb%b2%88-%eb%b0%94%ec%9d%b4%eb%9f%ac%ec%8a%a4-c-bfs-baekjoon/5161/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 20 Jan 2023 20:45:15 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2606]]></category>
		<category><![CDATA[2606번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[깊이 우선 탐색]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[바이러스]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2606]]></category>
		<category><![CDATA[백준 2606번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[컴파일 에러]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5161</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 2606번 '바이러스' 문제에 대한 글입니다. 'BFS' 를 사용하여 해결하였습니다. (This is an article about the 'virus' problem in BAEKJOON 2606. Resolved using 'BFS'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2606%eb%b2%88-%eb%b0%94%ec%9d%b4%eb%9f%ac%ec%8a%a4-c-bfs-baekjoon/5161/">백준 2606번 (바이러스, C++, 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:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">바이러스</h1>



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



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



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



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



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



<p class="has-medium-font-size wp-block-paragraph">신종 바이러스인 웜 바이러스는 네트워크를 통해 전파된다. </p>



<p class="has-medium-font-size wp-block-paragraph">한 컴퓨터가 웜 바이러스에 걸리면 그 컴퓨터와 네트워크 상에서 연결되어 있는 모든 컴퓨터는 웜 바이러스에 걸리게 된다.</p>



<p class="has-medium-font-size wp-block-paragraph">예를 들어 7대의 컴퓨터가 &lt;그림 1>과 같이 네트워크 상에서 연결되어 있다고 하자. </p>



<p class="has-medium-font-size wp-block-paragraph">1번 컴퓨터가 웜 바이러스에 걸리면 웜 바이러스는 2번과 5번 컴퓨터를 거쳐 3번과 6번 컴퓨터까지 전파되어 2, 3, 5, 6 네 대의 컴퓨터는 웜 바이러스에 걸리게 된다. </p>



<p class="has-medium-font-size wp-block-paragraph">하지만 4번과 7번 컴퓨터는 1번 컴퓨터와 네트워크상에서 연결되어 있지 않기 때문에 영향을 받지 않는다.</p>



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



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="455" height="274" src="https://lycos7560.com/wp-content/uploads/image-1016.png" alt="" class="wp-image-5162" srcset="https://lycos7560.com/wp-content/uploads/image-1016.png 455w, https://lycos7560.com/wp-content/uploads/image-1016-300x181.png 300w" sizes="(max-width: 455px) 100vw, 455px" /></figure>



<p class="has-medium-font-size wp-block-paragraph">어느 날 1번 컴퓨터가 웜 바이러스에 걸렸다. </p>



<p class="has-medium-font-size wp-block-paragraph">컴퓨터의 수와 네트워크 상에서 서로 연결되어 있는 정보가 주어질 때, </p>



<p class="has-medium-font-size wp-block-paragraph">1번 컴퓨터를 통해 웜 바이러스에 걸리게 되는 컴퓨터의 수를 출력하는 프로그램을 작성하시오.</p>



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



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



<p class="has-medium-font-size wp-block-paragraph">첫째 줄에는 컴퓨터의 수가 주어진다. </p>



<p class="has-medium-font-size wp-block-paragraph">컴퓨터의 수는 100 이하이고 각 컴퓨터에는 1번 부터 차례대로 번호가 매겨진다. </p>



<p class="has-medium-font-size wp-block-paragraph">둘째 줄에는 네트워크 상에서 직접 연결되어 있는 컴퓨터 쌍의 수가 주어진다. </p>



<p class="has-medium-font-size wp-block-paragraph">이어서 그 수만큼 한 줄에 한 쌍씩 네트워크 상에서 직접 연결되어 있는 컴퓨터의 번호 쌍이 주어진다.</p>



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



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



<p class="has-medium-font-size wp-block-paragraph">1번 컴퓨터가 웜 바이러스에 걸렸을 때, </p>



<p class="has-medium-font-size wp-block-paragraph">1번 컴퓨터를 통해 웜 바이러스에 걸리게 되는 컴퓨터의 수를 첫째 줄에 출력한다.</p>



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph"><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a> > <a href="https://www.acmicpc.net/category/55">한국정</a><a href="https://www.acmicpc.net/category/55" target="_blank" rel="noreferrer noopener">보</a><a href="https://www.acmicpc.net/category/55">올림피아드</a> > <a href="https://www.acmicpc.net/category/57" target="_blank" rel="noreferrer noopener">한국정보올림피아드시․도지역본선</a> > <a href="https://www.acmicpc.net/category/74" target="_blank" rel="noreferrer noopener">지역본선 2004</a> > <a href="https://www.acmicpc.net/category/detail/379" target="_blank" rel="noreferrer noopener">초등부</a> 3번</p>



<ul class="wp-block-list">
<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/chansol" target="_blank" rel="noreferrer noopener">chansol</a>, <a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a></li>



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



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



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



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



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



<p class="has-medium-font-size wp-block-paragraph">전에 해결한 문제가 BFS를 사용해서 이 문제도 BFS를 사용했다.</p>



<p class="has-medium-font-size wp-block-paragraph">시간 및 메모리가 충분하여 DFS, BFS 등 다양한 그래프 탐색을 적용 가능할 듯 </p>



<div style="height:39px" 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="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;queue>

using namespace std;

// 컴퓨터의 수 N, 연결수 K
int N, K, B, cnt = 0;

queue&lt;int> myQueue;

pair&lt;int, int> temp;

// 연결을 나타낸다.
bool connect[101][101];

// 컴퓨터의 감염 유무
bool computer[101];


int main()
{
	cin >> N >> K;

	for (int i = 1; i &lt;= K; i++) {
		cin >> temp.first >> temp.second;
		// 양방향으로 연결
		connect[temp.first][temp.second] = true;
		connect[temp.second][temp.first] = true;
	}
	
	// 1번 컴퓨터를 감염시키고
	computer[1] = true;
	myQueue.push(1); // 큐에 넣어준다.

	// BFS 탐색 시작
	while (!myQueue.empty()) {

		B = myQueue.front();
		myQueue.pop();

		for (int i = 1; i &lt;= N; i++) {

			// 컴퓨터가 연결이 되지 않았다. => 넘어간다.
			if (connect[B][i] == false &amp;&amp; connect[i][B] == false) continue;
			else if (computer[i] == true) continue; 
			// 이미 감염이 되어있다. => 넘어간다.

			// 해당 컴퓨터를 감염시키고
			computer[i] = true;
			cnt++; // 감염된 카운트를 올려준다.
			myQueue.push(i); // 큐에 넣어준다.
		}
	}

	cout &lt;&lt; cnt;

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1027" height="145" src="https://lycos7560.com/wp-content/uploads/image-1017.png" alt="" class="wp-image-5163" srcset="https://lycos7560.com/wp-content/uploads/image-1017.png 1027w, https://lycos7560.com/wp-content/uploads/image-1017-300x42.png 300w, https://lycos7560.com/wp-content/uploads/image-1017-768x108.png 768w" sizes="(max-width: 1027px) 100vw, 1027px" /></figure>



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



<p class="has-medium-font-size wp-block-paragraph">복사 붙여넣기를 잘못해서 컴파일 에러가 났다. ㄷㄷ</p>



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



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2606%eb%b2%88-%eb%b0%94%ec%9d%b4%eb%9f%ac%ec%8a%a4-c-bfs-baekjoon/5161/">백준 2606번 (바이러스, C++, BFS) [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-2606%eb%b2%88-%eb%b0%94%ec%9d%b4%eb%9f%ac%ec%8a%a4-c-bfs-baekjoon/5161/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
