Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <array>
- using namespace std;
- int father[200000+5];
- bool odwiedzone[200000+5];
- bool pocz_sasiedzi[2000+2][2000+2];
- bool aktu_sasiedzi[2000+2][2000+2];
- int n;
- void Divide(int w)
- {
- for(int i=0; i<=n; i++)
- {
- if(aktu_sasiedzi[w][i] == 1)
- {aktu_sasiedzi[w][i] = 0; aktu_sasiedzi[i][w] = 0;}
- }
- }
- void Add(int w)
- {
- for(int i=0; i<=n; i++)
- {
- if(pocz_sasiedzi[w][i] == 1)
- {aktu_sasiedzi[w][i] = 1; aktu_sasiedzi[i][w] = 1;}
- }
- }
- void DFS(int w)
- {
- odwiedzone[w] = true;
- for(int i=0; i<=n; i++)
- {
- if(aktu_sasiedzi[w][i] == 1 && odwiedzone[i] == false)
- DFS(i);
- }
- }
- void Ans(int A, int B)
- {
- for(int i=0; i<=n; i++)
- odwiedzone[i] = false;
- DFS(A);
- if(odwiedzone[B] == true)
- cout<<"TAK"<<endl;
- else
- cout<<"NIE"<<endl;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cin>>n;
- int t1;
- int t2;
- for(int i=1; i<n; i++)
- {
- cin>>t1;
- cin>>t2;
- pocz_sasiedzi[t1][t2] = 1;
- pocz_sasiedzi[t2][t1] = 1;
- aktu_sasiedzi[t1][t2] = 1;
- aktu_sasiedzi[t2][t1] = 1;
- }
- int q;
- cin>>q;
- char temp1;
- int temp2;
- int temp3;
- for(int i=0; i<q; i++)
- {
- cin>>temp1;
- cin>>temp2;
- if(temp1 == '?')
- {cin>>temp3; Ans(temp2, temp3);}
- else if(temp1 == '-')
- Divide(temp2);
- else
- Add(temp2);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement