Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int n;
- int m;
- vector <int> sas[200000+5];
- int s;
- int t;
- int b;
- bool found;
- int odw[200000+5];
- void DFS(int w)
- {
- //cout<<"dfs: "<<w<<endl;
- if(!found)
- {
- odw[w] = 1;
- if(w == t)
- found = 1;
- int ile_sas = sas[w].size();
- for(int i=0; i<ile_sas; i++)
- if(sas[w][i] != b && !odw[sas[w][i]])
- DFS(sas[w][i]);
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cin>>n;
- cin>>m;
- int t1;
- int t2;
- for(int i=1; i<=m; i++)
- {
- cin>>t1;
- cin>>t2;
- sas[t1].push_back(t2);
- sas[t2].push_back(t1);
- }
- int Q;
- cin>>Q;
- for(int i=1; i<=Q; i++)
- {
- cin>>s;
- cin>>t;
- cin>>b;
- for(int j=0; j<=n; j++)
- odw[j] = 0;
- found = 0;
- DFS(s);
- if(found)
- cout<<"TAK"<<'\n';
- else
- cout<<"NIE"<<'\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement