Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- vector<int>graph[2505];
- bool color[2505];
- int cost[2505],mx_boom,boom_day,counter,cst;
- void bfs(int a)
- {
- queue<int>Q;
- Q.push(a);
- color[a]=1;
- while(!Q.empty())
- {
- int u = Q.front();
- Q.pop();
- int sze = graph[u].size();
- for(int i=0; i<sze; ++i)
- {
- if(!color[graph[u][i]])
- {
- color[graph[u][i]]=1;
- cost[graph[u][i]]=cost[u]+1;
- Q.push(graph[u][i]);
- if(cst!=cost[graph[u][i]])
- {
- cst=cost[graph[u][i]];
- counter = 0;
- }
- counter++;
- if(counter>mx_boom)
- {
- mx_boom = counter;
- boom_day = cost[graph[u][i]];
- }
- }
- }
- }
- }
- int main()
- {
- int e,n,i,j,k,a,t;
- while(scanf("%d",&e)==1)
- {
- for(i=0; i<e; ++i)
- {
- scanf("%d",&n);
- for(j=1; j<=n; ++j)
- {
- scanf("%d",&a);
- graph[i].push_back(a);
- }
- }
- scanf("%d",&t);
- for(i=1; i<=t; ++i)
- {
- scanf("%d",&a);
- mx_boom = boom_day = 0;
- cst = counter = 0;
- bfs(a);
- if(!counter)
- {
- printf("0\n");
- }
- else
- {
- printf("%d %d\n",mx_boom,boom_day);
- }
- memset(color,false,sizeof(color));
- memset(cost,0,sizeof(cost));
- }
- for(i=0;i<=e;i++)
- {
- graph[i].clear();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment