Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include<vector>
- #include<queue>
- #include<algorithm>
- using namespace std;
- int main()
- {
- int t;
- t=1;
- while(t--)
- {
- queue<int> Q; //kolejnosc
- vector<bool> A;//czy dosiega
- vector<vector <int> > P;//polaczenia
- int p,k,m;//wierzcholki,krawedzie
- scanf("%d%d%d",&p,&k,&m);
- A.resize(10001,false);
- P.resize(10001);
- for(int i=0;i<m;i++)
- {
- int a,b;
- scanf("%d%d",&a,&b);
- P[a].push_back(b);
- P[b].push_back(a);
- }
- Q.push(p);
- A[p]=true;
- while(!Q.empty())
- {
- for(int i=0;i<P[Q.front()].size();i++)
- {
- if(A[P[Q.front()][i]]==false)
- Q.push(P[Q.front()][i]);
- A[Q.front()]=true;
- }
- Q.pop();
- }
- if(A[k])
- printf("TAK\n");
- else
- printf("NIE\n");
- }
- // system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment