判断是否有环(有向图)
int dfs(int v){ vis[v] = -1; for(int i = 1; i <= n; i++) { if(a[v][i] != 0 && !vis[i]) { dfs(i); vis[i]=1; } if(a[v][i] != 0 && vis[i] == -1){ printf("YES\n"); swi=true; return true; } } return false; }
int dfs(int v){ vis[v] = -1; for(int i = 1; i <= n; i++) { if(a[v][i] != 0 && !vis[i]) { dfs(i); vis[i]=1; } if(a[v][i] != 0 && vis[i] == -1){ printf("YES\n"); swi=true; return true; } } return false; }