Advertisement
a53

disjoint

a53
Jan 23rd, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n,m;
  7. cin>>n>>m;
  8. int CL[n+1];
  9. for(int i=1;i<=n;++i)
  10. CL[i]=i;
  11. int op,x,y;
  12. while(m--)
  13. {
  14. cin>>op>>x>>y;
  15. if(op==1)
  16. {
  17. if(CL[x]!=CL[y])
  18. {
  19. for(int i=1;i<=n;++i)
  20. if(i!=y&&CL[i]==CL[y])
  21. CL[i]=CL[x];
  22. CL[y]=CL[x];
  23. }
  24. }
  25. else
  26. if(CL[x]==CL[y])
  27. cout<<"DA\n";
  28. else
  29. cout<<"NU\n";
  30. }
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement