43 lines
909 B
C++
43 lines
909 B
C++
|
#include<stdio.h>
|
||
|
int main(){
|
||
|
int inDegree[65540]={0};
|
||
|
int node, destroy;
|
||
|
scanf("%d %d",&node,&destroy);
|
||
|
for(int i=0;i<node;i++){
|
||
|
int outDegNum;
|
||
|
scanf("%d",&outDegNum);
|
||
|
for(int i=0;i<outDegNum;i++){
|
||
|
int nodeNo;
|
||
|
scanf("%d",&nodeNo);
|
||
|
inDegree[nodeNo]+=1;
|
||
|
}
|
||
|
}
|
||
|
int canReach=1;
|
||
|
for(int i=1;i<node;i++){
|
||
|
if(inDegree[i]==0){
|
||
|
canReach=0;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
printf("%d\n",canReach);
|
||
|
if(!canReach){
|
||
|
for(int i=0;i<destroy;i++)
|
||
|
printf("0\n");
|
||
|
return 0;
|
||
|
}
|
||
|
for(int i=0;i<destroy;i++){
|
||
|
int from,to;
|
||
|
scanf("%d %d",&from,&to);
|
||
|
if(inDegree[to]>1){
|
||
|
printf("1\n");
|
||
|
}
|
||
|
else if(to==0)
|
||
|
{
|
||
|
printf("1\n");
|
||
|
}
|
||
|
else{
|
||
|
printf("0\n");
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}
|