Guest User

Untitled

a guest
Jun 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include<cstdio>
  2. #include<vector>
  3. #include<queue>
  4. #include<algorithm>
  5. using namespace std;
  6. int main()
  7. {
  8. int t;
  9. t=1;
  10. while(t--)
  11. {
  12. queue<int> Q; //kolejnosc
  13. vector<bool> A;//czy dosiega
  14. vector<vector <int> > P;//polaczenia
  15. int p,k,m;//wierzcholki,krawedzie
  16. scanf("%d%d%d",&p,&k,&m);
  17. A.resize(10001,false);
  18. P.resize(10001);
  19. for(int i=0;i<m;i++)
  20. {
  21. int a,b;
  22. scanf("%d%d",&a,&b);
  23. P[a].push_back(b);
  24. P[b].push_back(a);
  25. }
  26. Q.push(p);
  27. A[p]=true;
  28. while(!Q.empty())
  29. {
  30. for(int i=0;i<P[Q.front()].size();i++)
  31. {
  32. if(A[P[Q.front()][i]]==false)
  33. Q.push(P[Q.front()][i]);
  34. A[Q.front()]=true;
  35. }
  36. Q.pop();
  37. }
  38.  
  39. if(A[k])
  40. printf("TAK\n");
  41. else
  42. printf("NIE\n");
  43. }
  44. // system("pause");
  45. return 0;
  46. }
Add Comment
Please, Sign In to add comment