/***
Md. Nazmul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include <iomanip>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
#define lowest_int -2147483647
int visited[100001];
int parent[100001];
int headerInADay[100001];
vector<int>G[10001];
void bfs(int src)
{
queue<int>q;
memset(visited,0,sizeof(visited));
memset(parent,0,sizeof(parent));
q.push(src);
visited[src]=1;
headerInADay[src]=0;
int u,v;
while(!q.empty())
{
u = q.front();
q.pop();
for(int i=0; i<G[u].size() ; i++)
{
v = G[u][i];
if(headerInADay[v] == lowest_int)
{
headerInADay[v] = headerInADay[u] +1;
q.push(v);
}
}
}
}
void print_path(int src)
{
int occuer[2600];
memset(occuer,0,sizeof(occuer));
for(int i=0 ; i<2500 ; i++)
if(headerInADay[i] != lowest_int)
occuer[headerInADay[i]]++;
int maxi = -1 ;
int maxiDay;
for(int i=1 ; i<2510 ; i++)
{
if(maxi < occuer[i])
{
maxi = occuer[i];
maxiDay = i;
}
}
if(G[src].size() ==0)
pf("0\n");
else
pf("%d %d\n",maxi,maxiDay);
}
int main()
{
int node,edge,test,src,n;
sc("%d",&node);
for(int i=0 ; i<node ; i++)
{
sc("%d",&edge);
for(int j=0 ; j<edge ; j++)
{
sc("%d",&n);
G[i].pb(n);
}
}
sc("%d",&test);
for(int i=1 ; i<=test ; i++)
{
for(int j=0 ; j<2510 ; j++)
headerInADay[j] = lowest_int;
sc("%d",&src);
bfs(src);
print_path(src);
}
return 0;
}
Md. Nazmul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include <iomanip>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
#define lowest_int -2147483647
int visited[100001];
int parent[100001];
int headerInADay[100001];
vector<int>G[10001];
void bfs(int src)
{
queue<int>q;
memset(visited,0,sizeof(visited));
memset(parent,0,sizeof(parent));
q.push(src);
visited[src]=1;
headerInADay[src]=0;
int u,v;
while(!q.empty())
{
u = q.front();
q.pop();
for(int i=0; i<G[u].size() ; i++)
{
v = G[u][i];
if(headerInADay[v] == lowest_int)
{
headerInADay[v] = headerInADay[u] +1;
q.push(v);
}
}
}
}
void print_path(int src)
{
int occuer[2600];
memset(occuer,0,sizeof(occuer));
for(int i=0 ; i<2500 ; i++)
if(headerInADay[i] != lowest_int)
occuer[headerInADay[i]]++;
int maxi = -1 ;
int maxiDay;
for(int i=1 ; i<2510 ; i++)
{
if(maxi < occuer[i])
{
maxi = occuer[i];
maxiDay = i;
}
}
if(G[src].size() ==0)
pf("0\n");
else
pf("%d %d\n",maxi,maxiDay);
}
int main()
{
int node,edge,test,src,n;
sc("%d",&node);
for(int i=0 ; i<node ; i++)
{
sc("%d",&edge);
for(int j=0 ; j<edge ; j++)
{
sc("%d",&n);
G[i].pb(n);
}
}
sc("%d",&test);
for(int i=1 ; i<=test ; i++)
{
for(int j=0 ; j<2510 ; j++)
headerInADay[j] = lowest_int;
sc("%d",&src);
bfs(src);
print_path(src);
}
return 0;
}
No comments:
Post a Comment