I thought this question could be used and checked, but I thought it was wrong.
For example, if a-> B, A-> C is used to query the set, B and C cannot be connected, but B can be the apprentice of C, so this question is about topological sorting.
# Include <stdio. h> # include <string. h>IntD[105],Map[105] [105],Vis[105];IntMain(){IntI,J,K,F,N,M,U,V;While(~Scanf("% D",&N,&M)){If(N=0)Break;Memset(D,0,Sizeof(D));Memset(Map,0,Sizeof(Map));Memset(Vis,0,Sizeof(Vis));For(I=1;I<=M;I++ ){Scanf("% D",&U,&V);If(!Map[U] [V]) // This is very important because there may be repeated Input Points {Map[U] [V] =1;D[V] ++ ;}}For(I=0;I<N;I++ ){F=0;For(J=0;J<N;J++ ){If(D[J] =0&&Vis[J] =0)// It is used to process several nodes with an inbound value of 0.{Vis[J] =1;For(K=0;K<N;K++)If(Map[J] [K])D[K] --;F=1;Break;// If a value of 0 is found, the process ends.}}If(F=0)// If the node is not completely input and the node with an inbound degree of 0 is not displayed in the figure, it indicates that the node has a ring and is invalid.Break;}If(F=0)Printf("No \ n");ElsePrintf("Yes \ n");}}