文章
1
粉丝
77
获赞
5
访问
990
#include <stdio.h>
#include <stdbool.h>
#define MAX_NODES 1000
typedef struct {
int dest;
struct Node* next;
} Node;
typedef struct {
Node* head;
} AdjList[MAX_NODES];
bool hasCycleUtil(int node, bool visited[], bool onPath[], AdjList graph, int n) {
visited[node] = true;
onPath[node] = true;
Node* neighbor = graph[node].head;
while (neighbor != NULL) {
int nextNode = neighbor->dest;
if (!visited[nextNode]) {
if (hasCycleUtil(nextNode, visited, onPath, graph, n)) {
return true;
}
} else if (onPath[nextNode]) {
return true;
}
&...
登录后发布评论
暂无评论,来抢沙发