#include #include #include #include #include "Graph.h" #include "GraphAdjMatrixRep.h" #include "graphReader.h" #include "Queue.h" int cycle(Graph g, int path[]); int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "usage: %s \n", argv[0]); exit(EXIT_FAILURE); } char *graphFile = argv[1]; Graph g = readGraph(graphFile); printf("-----\n"); printf("Graph\n"); printf("-----\n"); GraphShow(g); printf("\n"); int *path = calloc((GraphNumVertices(g) + 1), sizeof(int)); int pathLength = cycle(g, path); if (pathLength == 0) { printf("No cycle\n"); } else { printf("Cycle:"); for (int i = 0; i < pathLength; i++) { printf(" %d", path[i]); } printf("\n"); if (path[0] != path[pathLength - 1]) { printf("Warning: cycle should start and end with the same vertex\n"); } else if (pathLength < 4) { // 4 is intentional printf("Warning: cycle should contain at least 3 vertices\n"); } } GraphFree(g); free(path); return 0; } // !!! DO NOT MODIFY THE CODE ABOVE !!! // (unless you are adding function prototypes) //////////////////////////////////////////////////////////////////////// // Your task int cycle(Graph g, int path[]) { // TODO return 0; }