int main(void) { /* read graph from stdin */ graph_t graph = graph_from_file(stdin); assert(graph != NULL); /* run kruskal */ graph_t mst = kruskal(graph); /* dump graph */ graph_dump(mst, stdout); /* dump total weight */ printf("\n# MST : %u\n", mst_total_weight(mst)); /* destroy both graphs */ graph = graph_destroy(graph); mst = graph_destroy(mst); }
int main(void) { /* read graph from stdin */ graph_t graph = graph_from_file(stdin); assert(graph != NULL); /* run kruskal */ graph_t mst = kruskal(graph); /* dump graph */ graph_dump(mst, stdout); /* dump total weight */ printf("\n# MST : %u\n", mst_total_weight(mst)); /* dump whether has a cycle */ if (graph_has_cycle(mst)) { printf("# Has a cycle: YES\n"); } else { printf("# Has a cycle: NO\n"); } /* dump total connected components */ printf("# Connected components: %u\n", graph_connected_components(mst)); /* destroy both graphs */ graph = graph_destroy(graph); mst = graph_destroy(mst); }