/***
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 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))
#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
int n,a,b,m,d,v;
vector<int>graph[1001] ;
int visited[10001];
queue<int>q ;
void check_graph(int p)
{
memset(visited,0,sizeof(visited));
q.push(p);
while(!q.empty())
{
int u = q.front();
q.pop() ;
for(int i=0 ; i<graph[u].size() ; i++)
{
v = graph[u][i];
if(!visited[v])
{
visited[v] =1;
q.push(v);
}
}
}
int cnt =0;
for(int i=0 ; i<n ; i++)
if(!visited[i]) cnt++;
pf("%d",cnt);
for(int i=0 ; i<n ; i++)
if(!visited[i])
pf(" %d",i+1);
pf("\n");
}
int main()
{
while(1)
{
sc("%d",&n);
if(n==0)
break;
while(1)
{
sc("%d",&a);
if(a==0)
break;
while(1)
{
sc("%d",&b);
if(b==0)
break;
graph[a-1].pb(b-1);
}
}
sc("%d",&m);
for(int i=0 ; i<m ; i++)
{
sc("%d",&d);
check_graph(d-1);
}
for(int i=0 ; i<n ; i++)
graph[i].clear();
}
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 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))
#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
int n,a,b,m,d,v;
vector<int>graph[1001] ;
int visited[10001];
queue<int>q ;
void check_graph(int p)
{
memset(visited,0,sizeof(visited));
q.push(p);
while(!q.empty())
{
int u = q.front();
q.pop() ;
for(int i=0 ; i<graph[u].size() ; i++)
{
v = graph[u][i];
if(!visited[v])
{
visited[v] =1;
q.push(v);
}
}
}
int cnt =0;
for(int i=0 ; i<n ; i++)
if(!visited[i]) cnt++;
pf("%d",cnt);
for(int i=0 ; i<n ; i++)
if(!visited[i])
pf(" %d",i+1);
pf("\n");
}
int main()
{
while(1)
{
sc("%d",&n);
if(n==0)
break;
while(1)
{
sc("%d",&a);
if(a==0)
break;
while(1)
{
sc("%d",&b);
if(b==0)
break;
graph[a-1].pb(b-1);
}
}
sc("%d",&m);
for(int i=0 ; i<m ; i++)
{
sc("%d",&d);
check_graph(d-1);
}
for(int i=0 ; i<n ; i++)
graph[i].clear();
}
return 0;
}
No comments:
Post a Comment