///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
int ar[102][102],vis[102],n;
void dfs(int u)
{
for (int i=1; i<=n; i++)
{
if (ar[u][i]==1&&vis[i]==0)
{
vis[i]=1;
dfs(i);
}
}
return;
}
main()
{
// int n;
while(cin>>n)
{
if(n==0)
break;
for(int i=0; i<101; i++)
{
for(int j=0; j<102; j++)
{
ar[i][j]=0;
}
}
int x,x1,q,s;
while(cin>>x&&x!=0)
{
while(cin>>x1&&x1!=0)
{
ar[x][x1]=1;
}
}
cin>>q;
while(q--)
{
scanf("%d",&s);
int ans = 0;
for (int i=0;i<=n;i++)
vis[i]=0;
dfs(s);
for (int i=1; i<=n; i++)
if (vis[i]==0)
ans++;
printf("%d",ans);
for (int i=1; i<=n; i++)
if (vis[i]==0)
printf(" %d",i);
cout<<endl;
}
}
}
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
int ar[102][102],vis[102],n;
void dfs(int u)
{
for (int i=1; i<=n; i++)
{
if (ar[u][i]==1&&vis[i]==0)
{
vis[i]=1;
dfs(i);
}
}
return;
}
main()
{
// int n;
while(cin>>n)
{
if(n==0)
break;
for(int i=0; i<101; i++)
{
for(int j=0; j<102; j++)
{
ar[i][j]=0;
}
}
int x,x1,q,s;
while(cin>>x&&x!=0)
{
while(cin>>x1&&x1!=0)
{
ar[x][x1]=1;
}
}
cin>>q;
while(q--)
{
scanf("%d",&s);
int ans = 0;
for (int i=0;i<=n;i++)
vis[i]=0;
dfs(s);
for (int i=1; i<=n; i++)
if (vis[i]==0)
ans++;
printf("%d",ans);
for (int i=1; i<=n; i++)
if (vis[i]==0)
printf(" %d",i);
cout<<endl;
}
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন