/***
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
verdict: accepted
***/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#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))
vector<in>G[1001] ;
queue<in>q ;
in node , visited[1001] , level[1001],cnt,data[1001];
in a,b ,src,v, u ,test , m;
void BFS()
{
src = m-1 ;
q.push(src) ;
//visited[src] =1 ;
while(!q.empty())
{
u = q.front() ;
q.pop() ;
for(in j=0 ; j<G[u].size() ; j++)
{
v = G[u][j] ;
if(!visited[v])
{
visited[v] =1 ;
q.push(v) ;
}
}
}
cnt =0 ;
for(in k=0 ; k<node ; k++)
{
if(!visited[k])
cnt++ ;
}
pf("%d",cnt) ;
for(in k=0 ; k<node ; k++)
{
if(!visited[k])
pf(" %d",k+1) ;
}
pf("\n") ;
}
int main()
{
while(cin>>node && node)
{
for(in i=0 ; i<=node ; i++)
G[i].clear() ;
while(cin>>a && a)
{
while(cin>>b &&b)
{
G[a-1].push_back(b-1) ;
}
}
cin>>test ;
for(in i=0 ; i<test ; i++)
{
cin>>m ;
memset(visited , 0 , sizeof(visited)) ;
BFS() ;
}
}
return 0 ;
}
Md. Namzul Hasan
Shahjalal University of Science & technology,sylhet.
hasan08sust@gmail.com
verdict: accepted
***/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cctype>
#include<sstream>
#include<stdlib.h>
#include<map>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#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))
vector<in>G[1001] ;
queue<in>q ;
in node , visited[1001] , level[1001],cnt,data[1001];
in a,b ,src,v, u ,test , m;
void BFS()
{
src = m-1 ;
q.push(src) ;
//visited[src] =1 ;
while(!q.empty())
{
u = q.front() ;
q.pop() ;
for(in j=0 ; j<G[u].size() ; j++)
{
v = G[u][j] ;
if(!visited[v])
{
visited[v] =1 ;
q.push(v) ;
}
}
}
cnt =0 ;
for(in k=0 ; k<node ; k++)
{
if(!visited[k])
cnt++ ;
}
pf("%d",cnt) ;
for(in k=0 ; k<node ; k++)
{
if(!visited[k])
pf(" %d",k+1) ;
}
pf("\n") ;
}
int main()
{
while(cin>>node && node)
{
for(in i=0 ; i<=node ; i++)
G[i].clear() ;
while(cin>>a && a)
{
while(cin>>b &&b)
{
G[a-1].push_back(b-1) ;
}
}
cin>>test ;
for(in i=0 ; i<test ; i++)
{
cin>>m ;
memset(visited , 0 , sizeof(visited)) ;
BFS() ;
}
}
return 0 ;
}
No comments:
Post a Comment