<?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/%ec%84%9c%eb%a1%9c%ec%86%8c-%ec%a7%91%ed%95%a9/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Fri, 14 Jul 2023 22:06:49 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</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>알고리즘 – 유니온 파인드(Union find) &#038; 서로소 집합(Disjoint Set)</title>
		<link>https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%9c%a0%eb%8b%88%ec%98%a8-%ed%8c%8c%ec%9d%b8%eb%93%9cunion-find-%ec%84%9c%eb%a1%9c%ec%86%8c-%ec%a7%91%ed%95%a9disjoint-set/33666/</link>
					<comments>https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%9c%a0%eb%8b%88%ec%98%a8-%ed%8c%8c%ec%9d%b8%eb%93%9cunion-find-%ec%84%9c%eb%a1%9c%ec%86%8c-%ec%a7%91%ed%95%a9disjoint-set/33666/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 05 Mar 2023 10:21:46 +0000</pubDate>
				<category><![CDATA[기타]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Disjoint Set]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[Union-Find]]></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>
		<guid isPermaLink="false">https://lycos7560.com/?p=33666</guid>

					<description><![CDATA[<p>유니온 파인드(Union find) &#038; 서로소 집합(Disjoint Set) 알고리즘에 대한 글입니다. (This article is about the Union find &#038; Disjoint Set algorithm.)</p>
<p>The post <a href="https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%9c%a0%eb%8b%88%ec%98%a8-%ed%8c%8c%ec%9d%b8%eb%93%9cunion-find-%ec%84%9c%eb%a1%9c%ec%86%8c-%ec%a7%91%ed%95%a9disjoint-set/33666/">알고리즘 – 유니온 파인드(Union find) &#038; 서로소 집합(Disjoint Set)</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>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-f818938d      "
					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="#유니온-파인드union-find-서로소-집합disjoint-set" class="uagb-toc-link__trigger">유니온 파인드(Union find) &amp; 서로소 집합(Disjoint Set)?</a><li class="uagb-toc__list"><a href="#예제-코드-c" class="uagb-toc-link__trigger">예제 코드 C++</a><li class="uagb-toc__list"><a href="#백준-union-find-algorithm-문제" class="uagb-toc-link__trigger">백준 Union find Algorithm 문제</a></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading has-large-font-size">유니온 파인드(Union find) &amp; 서로소 집합(Disjoint Set)?</h1>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>



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



<p class="has-medium-font-size">Union find는 대표적인 그래프 알고리즘으로</p>



<p class="has-medium-font-size"><strong>집합 내의 요소의 연결성을 효율적으로 추적하는 데 사용되는 데이터 구조 및 알고리즘</strong>입니다.</p>



<p class="has-medium-font-size">역으로 서로 연결되어 있지 않은 노드를 판별할 수도 있기 때문에&nbsp;<strong>서로소 집합 (Disjoint-set)</strong>이라고도 합니다.</p>



<p class="has-medium-font-size">알고리즘은 union과 find의 두 가지 연산으로 구성되어 있습니다.</p>



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



<p class="has-medium-font-size">-&gt; union 은 각 노드가 속한 집합을 1개로 합치는 연산</p>



<p class="has-medium-font-size">-&gt; find  특정 노드 A에 관해 A가 속한 대표 노드를 반환하는 연산</p>



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



<p class="has-medium-font-size">Union-Find 알고리즘은 집합 내 요소의 연결성을 추적하는 데 유용한 데이터 구조 및 알고리즘입니다. </p>



<p class="has-medium-font-size">이것은 많은 그래프 알고리즘에서 사용될 수 있으며 경로 압축 최적화로 O(log n) ~ O(n)의 시간 복잡도를 가집니다.</p>



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



<p></p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="알고리즘 코딩테스트 핵심이론 강의 - 유니온파인드" width="1778" height="1000" src="https://www.youtube.com/embed/klBh4ZglHYo?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div></figure>



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



<h1 class="wp-block-heading has-large-font-size">예제 코드 C++</h1>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>



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

// Initialize the parent array
void makeSet(int parent[], int n) {
    for (int i = 0; i &lt; n; i++) {
        parent[i] = i;
    }
}

// Find the root of the set containing node x
int find(int parent[], int x) {
    if (parent[x] != x) {
        parent[x] = find(parent, parent[x]); // Path compression
    }
    return parent[x];
}

// Merge the sets containing nodes x and y
void unite(int parent[], int x, int y) {
    int rootX = find(parent, x);
    int rootY = find(parent, y);
    parent[rootY] = rootX; // Make rootX the parent of rootY
}

int n = 5; // Number of nodes
int parent[5]; // Number of nodes

int main() {


    makeSet(parent, n); // Initialize the parent array

    // Merge sets containing nodes 2 and 4
    unite(parent, 2, 4);

    // Merge sets containing nodes 1 and 5
    unite(parent, 1, 5);

    // Merge sets containing nodes 1 and 2
    unite(parent, 1, 2);

    // Find the set of node 4
    int root4 = find(parent, 4);

    // Print the parent array
    for (int i = 0; i &lt; n; i++) {
        cout &lt;&lt; parent[i] &lt;&lt; " ";
    }
    cout &lt;&lt; endl;

    // Print the root of the set containing node 4
    cout &lt;&lt; "The root of the set containing node 4 is " &lt;&lt; root4 &lt;&lt; endl;

    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 fetchpriority="high" decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/03/image-22.png" alt="" class="wp-image-33750" width="1292" height="129" srcset="https://lycos7560.com/wp-content/uploads/2023/03/image-22.png 771w, https://lycos7560.com/wp-content/uploads/2023/03/image-22-300x30.png 300w, https://lycos7560.com/wp-content/uploads/2023/03/image-22-768x77.png 768w" sizes="(max-width: 1292px) 100vw, 1292px" /></figure>



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



<p class="has-medium-font-size">백준 예제</p>



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



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/03/image-21.png" alt="" class="wp-image-33737" width="1240" height="1226" srcset="https://lycos7560.com/wp-content/uploads/2023/03/image-21.png 1050w, https://lycos7560.com/wp-content/uploads/2023/03/image-21-300x297.png 300w, https://lycos7560.com/wp-content/uploads/2023/03/image-21-768x759.png 768w" sizes="(max-width: 1240px) 100vw, 1240px" /></figure>



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

constexpr int Max = 1000001;

// 유니온 root노드 배열
int uArr[Max];

int N, M, u, b, c;

//부모를 찾는 함수
//모든 경로가 부모를 가르키게 함
//상수 시간의 복잡도
int Find(int x)
{
    if (uArr[x] == x) return x;
    return uArr[x] = Find(uArr[x]);
}

//두 노드를 연결 시키는 것
//기준을 정해서 연결시키는 것이 헷갈리지 않음
//작은쪽이 부모 or 큰쪽이 부모
void Union(int x, int y)
{
    x = Find(x);
    y = Find(y);

    if (x != y) {
        if (x &lt; y) uArr[y] = x;
        else uArr[x] = y;
    }
}

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

    cin >> N >> M;
    // 유니온 배열 초기화
    for (int i = 0; i &lt;= N; i++) uArr[i] = i;

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

        cin >> u >> b >> c;

        if (u == 0) { // 합집합 연산
            Union(b, c);
        }
        else { // 질의
            if (Find(b) != Find(c)) cout &lt;&lt; "NO\n";
            else cout &lt;&lt; "YES\n";
        }
    }

    return 0;
}</pre>



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



<h1 class="wp-block-heading">백준 Union find Algorithm 문제</h1>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problemset?sort=ac_desc&amp;algo=81" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problemset?sort=ac_desc&amp;algo=81</a></p>



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



			<div class="wp-block-uagb-post-carousel uagb-post-grid  uagb-post__image-position-top uagb-post__image-enabled uagb-block-bfa50e23     uagb-post__arrow-outside uagb-post__items uagb-post__columns-5 is-carousel uagb-post__columns-tablet-2 uagb-post__columns-mobile-1" data-total="1" style="">

												<article class="uagb-post__inner-wrap">								<div class='uagb-post__image'>
									<a href="https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%9c%a0%eb%8b%88%ec%98%a8-%ed%8c%8c%ec%9d%b8%eb%93%9cunion-find-%ec%84%9c%eb%a1%9c%ec%86%8c-%ec%a7%91%ed%95%a9disjoint-set/33666/" target="_self" rel="bookmark noopener noreferrer"><img decoding="async" width="1024" height="640" src="https://lycos7560.com/wp-content/uploads/algorithm-wallpaper.jpg" class="attachment-large size-large" alt="" srcset="https://lycos7560.com/wp-content/uploads/algorithm-wallpaper.jpg 1024w, https://lycos7560.com/wp-content/uploads/algorithm-wallpaper-300x188.jpg 300w, https://lycos7560.com/wp-content/uploads/algorithm-wallpaper-768x480.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" />					</a>
									</div>
						<h4 class="uagb-post__title uagb-post__text">
				<a href="https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%9c%a0%eb%8b%88%ec%98%a8-%ed%8c%8c%ec%9d%b8%eb%93%9cunion-find-%ec%84%9c%eb%a1%9c%ec%86%8c-%ec%a7%91%ed%95%a9disjoint-set/33666/" target="_self" rel="bookmark noopener noreferrer">알고리즘 – 유니온 파인드(Union find) &#038; 서로소 집합(Disjoint Set)</a>
			</h4>
						<div class='uagb-post__text uagb-post-grid-byline'>
							</div>
						<div class="uagb-post__text uagb-post__cta wp-block-button">
				<a class="wp-block-button__link uagb-text-link" style="" href="https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%9c%a0%eb%8b%88%ec%98%a8-%ed%8c%8c%ec%9d%b8%eb%93%9cunion-find-%ec%84%9c%eb%a1%9c%ec%86%8c-%ec%a7%91%ed%95%a9disjoint-set/33666/" target="_self" rel="bookmark noopener noreferrer">더 읽기</a>
			</div>
			
									</article>
																<article class="uagb-post__inner-wrap">								<div class='uagb-post__image'>
									<a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1717%eb%b2%88-%ec%a7%91%ed%95%a9%ec%9d%98-%ed%91%9c%ed%98%84-c-union-find-baekjoon/33671/" target="_self" rel="bookmark noopener noreferrer"><img decoding="async" width="1024" height="535" src="https://lycos7560.com/wp-content/uploads/2022/10/boj-og-1-2048x1070-1-1024x535.png" class="attachment-large size-large" alt="" srcset="https://lycos7560.com/wp-content/uploads/2022/10/boj-og-1-2048x1070-1-1024x535.png 1024w, https://lycos7560.com/wp-content/uploads/2022/10/boj-og-1-2048x1070-1-300x157.png 300w, https://lycos7560.com/wp-content/uploads/2022/10/boj-og-1-2048x1070-1-768x401.png 768w, https://lycos7560.com/wp-content/uploads/2022/10/boj-og-1-2048x1070-1-1536x803.png 1536w, https://lycos7560.com/wp-content/uploads/2022/10/boj-og-1-2048x1070-1.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" />					</a>
									</div>
						<h4 class="uagb-post__title uagb-post__text">
				<a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1717%eb%b2%88-%ec%a7%91%ed%95%a9%ec%9d%98-%ed%91%9c%ed%98%84-c-union-find-baekjoon/33671/" target="_self" rel="bookmark noopener noreferrer">백준 1717번 (집합의 표현, C++, Union-Find) [BAEKJOON]</a>
			</h4>
						<div class='uagb-post__text uagb-post-grid-byline'>
							</div>
						<div class="uagb-post__text uagb-post__cta wp-block-button">
				<a class="wp-block-button__link uagb-text-link" style="" href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1717%eb%b2%88-%ec%a7%91%ed%95%a9%ec%9d%98-%ed%91%9c%ed%98%84-c-union-find-baekjoon/33671/" target="_self" rel="bookmark noopener noreferrer">더 읽기</a>
			</div>
			
									</article>
																<article class="uagb-post__inner-wrap">								<div class='uagb-post__image'>
									<a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2610%eb%b2%88-%ed%9a%8c%ec%9d%98%ec%a4%80%eb%b9%84-c-baekjoon/33706/" target="_self" rel="bookmark noopener noreferrer"><img decoding="async" width="1024" height="535" src="https://lycos7560.com/wp-content/uploads/2022/10/boj-og-1-2048x1070-1-1024x535.png" class="attachment-large size-large" alt="" srcset="https://lycos7560.com/wp-content/uploads/2022/10/boj-og-1-2048x1070-1-1024x535.png 1024w, https://lycos7560.com/wp-content/uploads/2022/10/boj-og-1-2048x1070-1-300x157.png 300w, https://lycos7560.com/wp-content/uploads/2022/10/boj-og-1-2048x1070-1-768x401.png 768w, https://lycos7560.com/wp-content/uploads/2022/10/boj-og-1-2048x1070-1-1536x803.png 1536w, https://lycos7560.com/wp-content/uploads/2022/10/boj-og-1-2048x1070-1.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" />					</a>
									</div>
						<h4 class="uagb-post__title uagb-post__text">
				<a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2610%eb%b2%88-%ed%9a%8c%ec%9d%98%ec%a4%80%eb%b9%84-c-baekjoon/33706/" target="_self" rel="bookmark noopener noreferrer">백준 2610번 (회의준비, C++) [BAEKJOON]</a>
			</h4>
						<div class='uagb-post__text uagb-post-grid-byline'>
							</div>
						<div class="uagb-post__text uagb-post__cta wp-block-button">
				<a class="wp-block-button__link uagb-text-link" style="" href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2610%eb%b2%88-%ed%9a%8c%ec%9d%98%ec%a4%80%eb%b9%84-c-baekjoon/33706/" target="_self" rel="bookmark noopener noreferrer">더 읽기</a>
			</div>
			
									</article>
																<article class="uagb-post__inner-wrap">								<div class='uagb-post__image'>
									<a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17352%eb%b2%88-%ec%97%ac%eb%9f%ac%eb%b6%84%ec%9d%98-%eb%8b%a4%eb%a6%ac%ea%b0%80-%eb%90%98%ec%96%b4-%eb%93%9c%eb%a6%ac%ea%b2%a0%ec%8a%b5%eb%8b%88%eb%8b%a4-c-baekjoon/33762/" target="_self" rel="bookmark noopener noreferrer"><img decoding="async" width="1920" height="1003" src="https://lycos7560.com/wp-content/uploads/boj-og.png" class="attachment-large size-large" alt="" srcset="https://lycos7560.com/wp-content/uploads/boj-og.png 1920w, https://lycos7560.com/wp-content/uploads/boj-og-300x157.png 300w, https://lycos7560.com/wp-content/uploads/boj-og-768x401.png 768w, https://lycos7560.com/wp-content/uploads/boj-og-1536x802.png 1536w, https://lycos7560.com/wp-content/uploads/boj-og-2048x1070.png 2048w" sizes="(max-width: 1920px) 100vw, 1920px" />					</a>
									</div>
						<h4 class="uagb-post__title uagb-post__text">
				<a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17352%eb%b2%88-%ec%97%ac%eb%9f%ac%eb%b6%84%ec%9d%98-%eb%8b%a4%eb%a6%ac%ea%b0%80-%eb%90%98%ec%96%b4-%eb%93%9c%eb%a6%ac%ea%b2%a0%ec%8a%b5%eb%8b%88%eb%8b%a4-c-baekjoon/33762/" target="_self" rel="bookmark noopener noreferrer">백준 17352번 (여러분의 다리가 되어 드리겠습니다!, C++) [BAEKJOON]</a>
			</h4>
						<div class='uagb-post__text uagb-post-grid-byline'>
							</div>
						<div class="uagb-post__text uagb-post__cta wp-block-button">
				<a class="wp-block-button__link uagb-text-link" style="" href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17352%eb%b2%88-%ec%97%ac%eb%9f%ac%eb%b6%84%ec%9d%98-%eb%8b%a4%eb%a6%ac%ea%b0%80-%eb%90%98%ec%96%b4-%eb%93%9c%eb%a6%ac%ea%b2%a0%ec%8a%b5%eb%8b%88%eb%8b%a4-c-baekjoon/33762/" target="_self" rel="bookmark noopener noreferrer">더 읽기</a>
			</div>
			
									</article>
											</div>
			


<div style="height:40px" 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="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%9c%a0%eb%8b%88%ec%98%a8-%ed%8c%8c%ec%9d%b8%eb%93%9cunion-find-%ec%84%9c%eb%a1%9c%ec%86%8c-%ec%a7%91%ed%95%a9disjoint-set/33666/">알고리즘 – 유니온 파인드(Union find) &#038; 서로소 집합(Disjoint Set)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%ec%9c%a0%eb%8b%88%ec%98%a8-%ed%8c%8c%ec%9d%b8%eb%93%9cunion-find-%ec%84%9c%eb%a1%9c%ec%86%8c-%ec%a7%91%ed%95%a9disjoint-set/33666/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1717번 (집합의 표현, C++, Union-Find) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1717%eb%b2%88-%ec%a7%91%ed%95%a9%ec%9d%98-%ed%91%9c%ed%98%84-c-union-find-baekjoon/33671/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1717%eb%b2%88-%ec%a7%91%ed%95%a9%ec%9d%98-%ed%91%9c%ed%98%84-c-union-find-baekjoon/33671/#comments</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 04 Mar 2023 12:52:39 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1717]]></category>
		<category><![CDATA[1717번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Disjoint Set]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[Union-Find]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1717]]></category>
		<category><![CDATA[백준 1717번]]></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=33671</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1717번 '집합의 표현' 문제에 대한 글입니다. Union-Find 알고리즘을 이용하여 해결하였습니다.  (This article is about the problem of 'expression of a set' in BAEKJOON 1717. It was solved using the Union-Find algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1717%eb%b2%88-%ec%a7%91%ed%95%a9%ec%9d%98-%ed%91%9c%ed%98%84-c-union-find-baekjoon/33671/">백준 1717번 (집합의 표현, C++, Union-Find) [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>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-4e6bf4a0      "
					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:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">집합의 표현</h1>



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



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



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">75296</td><td class="has-text-align-left" data-align="left">23857</td><td class="has-text-align-left" data-align="left">14435</td><td class="has-text-align-left" data-align="left">28.135%</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">초기에 n+1개의 집합 {0}, {1}, {2}, … , {n}이 있다.</p>



<p class="has-medium-font-size">여기에 합집합 연산과, 두 원소가 같은 집합에 포함되어 있는지를 확인하는 연산을 수행하려고 한다.</p>



<p class="has-medium-font-size">집합을 표현하는 프로그램을 작성하시오.</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">첫째 줄에 n, m이 주어진다.</p>



<p class="has-medium-font-size">m은 입력으로 주어지는 연산의 개수이다.</p>



<p class="has-medium-font-size">다음 m개의 줄에는 각각의 연산이 주어진다.</p>



<p class="has-medium-font-size">합집합은 0 a b의 형태로 입력이 주어진다.</p>



<p class="has-medium-font-size">이는 a가 포함되어 있는 집합과, b가 포함되어 있는 집합을 합친다는 의미이다.</p>



<p class="has-medium-font-size">두 원소가 같은 집합에 포함되어 있는지를 확인하는 연산은 1 a b의 형태로 입력이 주어진다.</p>



<p class="has-medium-font-size">이는 a와 b가 같은 집합에 포함되어 있는 지를 확인하는 연산이다.</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">1로 시작하는 입력에 대해서&nbsp;a와&nbsp;b가 같은 집합에 포함되어 있으면 &#8220;<code>YES</code>&#8221; 또는 &#8220;<code>yes</code>&#8220;를, </p>



<p class="has-medium-font-size">그렇지 않다면 &#8220;<code>NO</code>&#8221; 또는 &#8220;<code>no</code>&#8220;를 한 줄에 하나씩 출력한다.</p>



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



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



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



<li>1 ≤ m ≤ 100,000 </li>



<li>0 ≤ a, b ≤ n </li>



<li>a, b는 정수</li>



<li>a와 b는 같을 수도 있다.</li>
</ul>



<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 8
0 1 3
1 1 7
0 7 6
1 7 1
0 3 7
0 4 2
0 1 1
1 1 1</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="">NO
NO
YES</pre>



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



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



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



<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/njw1204" target="_blank" rel="noreferrer noopener">njw1204</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/175" target="_blank" rel="noreferrer noopener">자료 구조</a></li>



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



<h1 class="wp-block-heading">접근 방법</h1>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1266" height="1920" src="https://lycos7560.com/wp-content/uploads/2023/03/Notes_230304_214804.jpg" alt="" class="wp-image-33680" srcset="https://lycos7560.com/wp-content/uploads/2023/03/Notes_230304_214804.jpg 1266w, https://lycos7560.com/wp-content/uploads/2023/03/Notes_230304_214804-198x300.jpg 198w, https://lycos7560.com/wp-content/uploads/2023/03/Notes_230304_214804-768x1165.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/03/Notes_230304_214804-1013x1536.jpg 1013w" sizes="(max-width: 1266px) 100vw, 1266px" /></figure>



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



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



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

constexpr int Max = 1000001;

// 유니온 root노드 배열
int uArr[Max];

int N, M, u, b, c;

//부모를 찾는 함수
//모든 경로가 부모를 가르키게 함
//상수 시간의 복잡도
int Find(int x)
{
    if (uArr[x] == x) return x;
    return uArr[x] = Find(uArr[x]);
}

//두 노드를 연결 시키는 것
//기준을 정해서 연결시키는 것이 헷갈리지 않음
//작은쪽이 부모 or 큰쪽이 부모
void Union(int x, int y)
{
    x = Find(x);
    y = Find(y);

    if (x != y) {
        if (x &lt; y) uArr[y] = x;
        else uArr[x] = y;
    }
}

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

    cin >> N >> M;
    // 유니온 배열 초기화
    for (int i = 0; i &lt;= N; i++) uArr[i] = i;

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

        cin >> u >> b >> c;

        if (u == 0) { // 합집합 연산
            Union(b, c);
        }
        else { // 질의
            if (Find(b) != Find(c)) cout &lt;&lt; "NO\n";
            else cout &lt;&lt; "YES\n";
        }
    }

    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="912" height="131" src="https://lycos7560.com/wp-content/uploads/2023/03/image-17.png" alt="" class="wp-image-33676" srcset="https://lycos7560.com/wp-content/uploads/2023/03/image-17.png 912w, https://lycos7560.com/wp-content/uploads/2023/03/image-17-300x43.png 300w, https://lycos7560.com/wp-content/uploads/2023/03/image-17-768x110.png 768w" sizes="(max-width: 912px) 100vw, 912px" /></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="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-1717%eb%b2%88-%ec%a7%91%ed%95%a9%ec%9d%98-%ed%91%9c%ed%98%84-c-union-find-baekjoon/33671/">백준 1717번 (집합의 표현, C++, Union-Find) [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-1717%eb%b2%88-%ec%a7%91%ed%95%a9%ec%9d%98-%ed%91%9c%ed%98%84-c-union-find-baekjoon/33671/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
