2140=数据结构实验之图论十:判断给定图是否存在合法拓扑序列
#include <stdio.h> #include <stdlib.h> #include <string.h> int map[100][100],visited[100],du[100],flag,n,m,i,j,k; int main() { while(~scanf("%d %d",&n,&m)) { memset(map,0,sizeof(map)); memset(visited,0,sizeof(visited)); memset(du,0,sizeof(du)); while(m--) { int a,b; scanf("%d%d",&a,&b); map[a][b]=1; du[b]++; } for(i=1; i<=n; i++) { flag=0; for(j=1; j<=n; j++) { if(visited[j]==0&&du[j]==0) { visited[j]=1; for(k=1; k<=n; k++) { if(map[j][k]==1) du[k]--; } flag=1; break; } } } if(flag==1)printf("YES\n"); else printf("NO\n"); } return 0; }
相关推荐
rainchxy 2020-06-16
faiculty 2020-06-05
路漫 2020-03-26
dbhllnr 2020-02-22
niushao 2020-02-10
清溪算法 2020-01-17
waitwolf 2019-11-09
yishujixiaoxiao 2019-11-04
flymist 2012-04-13
uniqueleion 2012-03-10
hyderhan 2019-06-28
YUAN 2019-06-26
bluewelkin 2017-07-24
wangquannuaa 2018-08-13
gybheroin 2017-04-02
ernestlishun 2017-06-09
BitTigerio 2018-05-04
Moneycode 2018-02-20