Pages

বৃহস্পতিবার, ২ জানুয়ারী, ২০১৪

Solution code of uva 924


 #include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<stack>
using namespace std;
int main()
{
    //freopen("c:\\temp\\in.txt","r",stdin);
    int employe;
    while(scanf("%d",&employe)==1)
    {
        vector<int>graph[2501];
        for(int i=0;i<employe;i++)
        {
            int num;
            scanf("%d",&num);
            for(int j=1;j<=num;j++)
            {
               int c;
               cin>>c;
               if(i!=c)
               graph[i].push_back(c);

            }
        }
        int test_case;
        scanf("%d",&test_case);
        while(test_case--)
        {
            int source;
            scanf("%d",&source);
            queue<int>q;
            q.push(source);
            int visit[2501];
            memset(visit,0,sizeof visit);
            int coun[2501];
            memset(coun,0,sizeof visit);
            visit[source]=1;
            int boom_size=0,first_day;
            while(!q.empty())
            {
                int pop=q.front();q.pop();
                for(int i=0;i<graph[pop].size();i++)
                {
                    int v=graph[pop][i];
                     if(visit[v]==0)
                     {
                         visit[v]=visit[pop]+1;
                         q.push(v);
                         coun[visit[v]]=coun[visit[v]]+1;
                         if(boom_size<coun[visit[v]])
                         {
                             boom_size=coun[visit[v]];
                             first_day=visit[v];
                         }
                     }
                }
            }
            if(graph[source].size()<1)
                cout<<0;
            else cout<<boom_size<<" "<<first_day-1;
            cout<<endl;
        }
    }
    return 0;
}

0 comments:

একটি মন্তব্য পোস্ট করুন