Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int n;
  6. int m;
  7.  
  8. vector <int> sas[200000+5];
  9.  
  10.  
  11. int s;
  12. int t;
  13. int b;
  14. bool found;
  15.  
  16.  
  17. int odw[200000+5];
  18.  
  19. void DFS(int w)
  20. {
  21. //cout<<"dfs: "<<w<<endl;
  22. if(!found)
  23. {
  24.  
  25. odw[w] = 1;
  26. if(w == t)
  27. found = 1;
  28.  
  29. int ile_sas = sas[w].size();
  30. for(int i=0; i<ile_sas; i++)
  31. if(sas[w][i] != b && !odw[sas[w][i]])
  32. DFS(sas[w][i]);
  33.  
  34. }
  35. }
  36.  
  37.  
  38. int main()
  39. {
  40. ios_base::sync_with_stdio(0);
  41. cin.tie(0);
  42.  
  43. cin>>n;
  44. cin>>m;
  45.  
  46. int t1;
  47. int t2;
  48. for(int i=1; i<=m; i++)
  49. {
  50. cin>>t1;
  51. cin>>t2;
  52.  
  53. sas[t1].push_back(t2);
  54. sas[t2].push_back(t1);
  55. }
  56.  
  57. int Q;
  58. cin>>Q;
  59.  
  60.  
  61. for(int i=1; i<=Q; i++)
  62. {
  63. cin>>s;
  64. cin>>t;
  65. cin>>b;
  66.  
  67. for(int j=0; j<=n; j++)
  68. odw[j] = 0;
  69.  
  70. found = 0;
  71. DFS(s);
  72.  
  73. if(found)
  74. cout<<"TAK"<<'\n';
  75. else
  76. cout<<"NIE"<<'\n';
  77.  
  78. }
  79.  
  80.  
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement