标签:des style blog io color sp for div log
1 0 2 2 1 2 2 1
YES NO
#include<stdio.h> #include<string.h> int indegree[1000];//入度数组 int mapp[1000][1000]; int main() { int n, m; while(~scanf("%d%d", &n, &m)) { int x, y; int cnt=0; memset(mapp, 0, sizeof(mapp)); memset(indegree, 0, sizeof(indegree)); for(int i=0; i<m; i++) { scanf("%d%d", &x, &y); mapp[x][y] = 1; indegree[y]++;//如果x,y有边相连,令y点的入度加1 } for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) if(mapp[i][j] && indegree[i]==0)//每次找入度为0的点 indegree[j]--; for(int i=1; i<=n; i++) if(indegree[i]==0)//如果图结构符合拓扑排序的话,cnt会等于点个数 cnt++; if(cnt==n)//不存在环 printf("YES\n"); else printf("NO\n"); } return 0; }
标签:des style blog io color sp for div log
原文地址:http://www.cnblogs.com/6bing/p/4117786.html