Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- vector<int>vec[1000];
- int level[1000];
- void bfs(int s,int d)
- {
- int vis[1000]= {0};
- queue<int>q;
- queue<int>q1;
- vis[s]=1;
- level[s]=0;
- q.push(s);
- q1.push(s);
- while(!q.empty ())
- {
- int x=q.front();
- cout<<"X = "<<x<<endl;
- for(int l=0; l<vec[x].size(); l++)
- {
- int y=vec[x][l];
- if(vis[y]==0)
- {
- vis[y]=1;
- level[y]=level[x]+1;
- cout<<"l = "<<l<<endl;
- cout<<"Level of "<<y<<" = "<<level[y]<<endl;
- q.push(y);
- }
- /*loop ses na koria baroy khene ? */
- }
- cout<<"Baroise"<<endl;
- q.pop();
- }
- printf("%2d to %2d: %d\n", s, d, level[d]);
- }
- int main()
- {
- int p,q,r,s,h,c=0;
- while(cin>>p)
- {
- for(int i=0; i<p; i++)
- {
- cin>>q;
- vec[1].push_back(q);
- vec[q].push_back(1);
- }
- for(int j=2; j<20; j++)
- {
- cin>>r;
- for(int i=0; i<r; i++)
- {
- cin>>h;
- vec[j].push_back(h);
- vec[h].push_back(j);
- }
- }
- cin>>s;
- printf("Test Set #%d\n",++c);
- int s1,s2;
- for(int k=0; k<s; k++)
- {
- cin>>s1>>s2;
- bfs(s1,s2);
- }
- cout<<endl;
- for(int i=0; i<=20; i++)
- {
- vec[i].clear();
- }
- }
- return 0;
- }
- //test case
- /*
- 1 3
- 2 3 4
- 3 4 5 6
- 1 6
- 1 7
- 2 12 13
- 1 8
- 2 9 10
- 1 11
- 1 11
- 2 12 17
- 1 14
- 2 14 15
- 2 15 16
- 1 16
- 1 19
- 2 18 19
- 1 20
- 1 20
- 5
- 1 20
- 2 9
- 19 5
- 18 19
- 16 20
- 4 2 3 5 6
- 1 4
- 3 4 10 5
- 5 10 11 12 19 18
- 2 6 7
- 2 7 8
- 2 9 10
- 1 9
- 1 10
- 2 11 14
- 3 12 13 14
- 3 18 17 13
- 4 14 15 16 17
- 0
- 0
- 0
- 2 18 20
- 1 19
- 1 20
- 6
- 1 20
- 8 20
- 15 16
- 11 4
- 7 13
- 2 16
- */
Advertisement
Add Comment
Please, Sign In to add comment