Nuclear_Fish_cyq @ 2024-01-25 19:46:26
这份代码是我在学并查集之前写的,目测
#include <bits/stdc++.h>
using namespace std;
int n, m, a[10005];
void add(int q, int p){
int t = a[q];
for(int i = 0; i < n; i++){
if(a[i] == t){
a[i] = a[p];
}
}
return;
}
void check(int q, int p){
if(a[q] == a[p]){
cout << "Y" << endl;
}
else{
cout << "N" << endl;
}
return;
}
int main(){
std::ios::sync_with_stdio(false);
cin >> n >> m;
for(int i = 0; i < n; i++){
a[i] = i;
}
int t, q, p;
for(int i = 0; i < m; i++){
cin >> t >> q >> p;
q--;
p--;
if(t == 1){
add(q, p);
}
else{
check(q, p);
}
}
}
by SugarKite @ 2024-01-25 20:05:08
你谷评测姬tql