2138=数据结构实验之图论三:判断可达性
#include <stdio.h> #include <stdlib.h> #include <string.h> #define INF 0x3f3f3f3f int map[1000][1000],visited[1000]; int n,m; int flag; void DFS(int t) { int i; visited[t]=1; for(i=n; i>=1; i--) { if(visited[i]==0&&map[t][i]==1) { DFS(i); } } } int main() { while(~scanf("%d %d",&n,&m)) { int i; memset(map,0,sizeof(map)); memset(visited,0,sizeof(visited)); for(i=1; i<=m; i++) { int a,b; scanf("%d %d",&a,&b); map[a][b]=1; } DFS(n); if(visited[1]==1) printf("YES\n"); else printf("NO\n"); } return 0; }
相关推荐
koushr 2020-11-12
zhangxiafll 2020-11-13
kikaylee 2020-10-31
范范 2020-10-28
MILemon 2020-10-22
hugebawu 2020-10-12
LauraRan 2020-09-28
shenwenjie 2020-09-24
omyrobin 2020-09-23
guangcheng 2020-09-22
qiangde 2020-09-13
hanyujianke 2020-08-18
晨曦之星 2020-08-14
xiesheng 2020-08-06
KAIrving 2020-08-02
xiesheng 2020-08-02
范范 2020-07-30
chenfei0 2020-07-30