This question I do not say, basic (okay without basic) is a template title reads + + disjoint-set output, the perfect ending
1 #include<set> 2 #include<map> 3 #include<list> 4 #include<queue> 5 #include<stack> 6 #include<string> 7 #include<cmath> 8 #include<ctime> 9 #include<vector> 10 #include<bitset> 11 #include<memory> 12 #include<utility> 13 #include<cstdio> 14 #include<sstream> 15 #include<iostream> 16 #include<cstdlib> 17 #include<cstring> 18#include <algorithm> . 19 the using namespace STD; 20 is 21 is int n-, m, P; 22 is int ZY [ 5005 ]; 23 is 24 int Find ( int Z) {// find the set of metadata representing the 25 IF (Z == ZY [Z]) { 26 is return Z; 27 } 28 return ZY [Z] = Find (ZY [Z]); 29 } 30 31 is int main () { 32 Scanf ( " % D% D% D " , & n-, & m , & P); 33 is for(int i=1;i<=n;i++){ 34 zy[i]=i; 35 } 36 for(int i=1;i<=m;i++){ 37 int z,y; 38 scanf("%d%d",&z,&y); 39 zy[find(z)]=zy[find(y)];//合并 40 } 41 for(int i=1;i<=p;i++){ 42 int z,y; 43 scanf("%d%d" , & Z, & Y); 44 is IF (Find (Z) == Find (Y)) {// set the same in 45 the printf ( " Yes \ n- " ); 46 is } 47 the else { 48 the printf ( " No \ n- " ); 49 } 50 } 51 is return 0 ; 52 is }
Ah Since water problems that have nothing to talk about, so the child