Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n, c[501];
- void Init()
- {
- for(int i = 1; i <= n; i++)
- c[i] = i;
- }
- void Update(int x, int y)
- {
- int a = c[x], b = c[y];
- if(a > b)
- swap(a,b);
- for(int i = 1; i <= n; i++)
- if(c[i] == b)
- c[i] = a;
- }
- bool Query(int x, int y)
- {
- return c[x] == c[y];
- }
- int main()
- {
- int m;
- cin >> n >> m;
- Init();
- for(int i = 1; i <= m; i++)
- {
- int x, y, op;
- cin >> op >> x >> y;
- if(op == 1)
- Update(x,y);
- else
- {
- if(Query(x,y))
- cout << "DA\n";
- else
- cout << "NU\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement