Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C++ Compiler.
- Code, Compile, Run and Debug C++ program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <bits/stdc++.h>
- #define pb push_back
- using namespace std;
- int m,d;
- struct node{
- int n,d;
- };
- vector<int> G[3000];
- bool visit[3000];
- int value[3000];
- void bfs(int s){
- queue<node> Q;
- node nod;
- nod.n=s;
- nod.d=1;
- Q.push(nod);
- visit[s] = true;
- while(!Q.empty()){
- nod = Q.front();
- Q.pop();
- int u = nod.n;
- int day = nod.d;
- int cnt=0;
- for(int i=0;i<G[u].size();i++){
- int v = G[u][i];
- if(visit[v]==false){
- visit[v] = true;
- nod.n = v;
- nod.d = day+1;
- Q.push(nod);
- cnt++;
- }
- }
- value[day]+=cnt;
- if(value[day]>m){
- m = value[day];
- d = day;
- }
- }
- }
- void print(){
- if(m==0) printf("0\n");
- else printf("%d %d\n",m,d);
- }
- int main()
- {
- int e;
- scanf("%d",&e);
- getchar();
- for(int i=0;i<e;i++){
- int N;
- scanf("%d",&N);
- while(N--){
- int f;
- scanf("%d",&f);
- G[i].pb(f);
- }
- }
- int t;
- scanf("%d",&t);
- getchar();
- while(t--){
- int s;
- scanf("%d",&s);
- bfs(s);
- print();
- memset(visit,false,sizeof(visit));
- memset(value,0,sizeof(value));
- m=0;
- d=0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment