bool Istree() { bool f=1; int component=0; int root=0; for(int i=0; i<Max; i++) { if(!visit[i]) { continue; } if(i==father[i]) { component++; } if(Indegree[i]==0) { root++; } else if(Indegree[i]>1) { f=0; } } if(component!=1||root!=1) { f=0; } if(component==0&&root==0) { f=1; } return f; } 判断为树,一个根结点,度为0,其余结点度为1,各个结点同属一个集合!!!