From 6069f24be1cdfd5ac9b4003ac1592def05903b89 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Sun, 1 Nov 2020 21:54:10 +0800 Subject: [PATCH] =?UTF-8?q?P3367=20=E3=80=90=E6=A8=A1=E6=9D=BF=E3=80=91?= =?UTF-8?q?=E5=B9=B6=E6=9F=A5=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R41046097 --- problem/P3367/P3367.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 problem/P3367/P3367.cpp diff --git a/problem/P3367/P3367.cpp b/problem/P3367/P3367.cpp new file mode 100644 index 00000000..2181e65d --- /dev/null +++ b/problem/P3367/P3367.cpp @@ -0,0 +1,27 @@ +#include + +using namespace std; + +int f[1000005]; + +int find(int x) { + return f[x] == x ? x : f[x] = find(f[x]); +} + +int main() { + int n, m, z, x, y; + cin >> n >> m; + for(int i = 0; i < n ; i++) { + f[i] = i; + } + while(m--) { + cin >> z >> x >> y; + if(z == 1) { + f[find(x)] = find(y); + } + else { + cout << (find(x) == find(y) ? "Y" : "N") << endl; + } + } + return 0; +}