//Made by Bruno Emori (RA 88736) & Christian Nakata (RA90558) //Algoritmos em Grafos - Prof Rodrigo Calvo //Universidade Estadual de Maringá - 2016 int main() { int nVertex, nEdges, graphType, v1, v2, edgeWeight, count; fscanf(stdin, "%i", &nVertex); fscanf(stdin, "%i", &nEdges); fscanf(stdin, "%i", &graphType); if ((graphType != 0) && (graphType != 1)) { printf("Graph type must be (0) - Undirected graph, or (1) - Directed graph.\n"); return 0; } adjListBlock *adjList[nVertex]; createAdjList(adjList, nVertex); while (fscanf(stdin, "%i", &v1) != EOF) { fscanf(stdin, "%i", &v2); fscanf(stdin, "%i", &edgeWeight); insertAdjList(adjList, v1, v2, edgeWeight); if (!graphType) insertAdjList(adjList, v2, v1, edgeWeight); } printf("Number of vertices: %i.\n", nVertex); printf("Number of edges: %i.\n", nEdges); if (!graphType) printf("Graph Type: Undirected Graph\n"); else printf("Graph Type: Directed Graph\n"); printf("\nEdges:\n"); for (count = 0; count < nVertex; count++) { printf("Vertex %i: ", count); printAdjList(adjList, count); printf("\n"); } printf("\n\nDeep First Search:\n"); deepFirstSearch(adjList, nVertex); printf("\n\nBreadth First Search:\n"); breadthFirstSearch(adjList, nVertex, 0); printf("\n\nComponents:\n"); connectedComponent(adjList, nVertex); if (graphType) { printf("\n\nShortest path: (Using Dijkstra's Algorithm)\n"); dijkstra(adjList, nVertex, 0); } printf("End Program.\n"); return 0; }
void main() { int capacity=VertexNum; // 顶点个数 AdjList adjList; // 邻接表 int row=VertexNum, i, j; int adjArray[VertexNum][VertexNum] = { {0, 1, 0, 1, 0, 0, 0}, {1, 0, 1, 0, 0, 0, 0}, {0, 1, 0, 1, 0, 0, 1}, {1, 0, 1, 0, 1, 1, 0}, {0, 0, 0, 1, 0, 1, 0}, {0, 0, 0, 1, 1, 0, 0}, {0, 0, 1, 0, 0, 0, 0}, }; // init adjacency list. adjList = init(capacity); if(adjList==NULL) { return; } printf("\n\n\t === reviww for DFS applie into biconnectivity graph ==="); printf("\n\t === build adjacency list ===\n"); for(i=0;i<row;i++) { visited[i]=0; for(j=0; j<row; j++) { if(adjArray[i][j]) { insertAdjList(adjList, i, j+1, adjArray[i][j]); // 插入节点到邻接表.(无向图权值为全1) } } } printAdjList(adjList); // 使用dfs 遍历无向图. dfs_find_articulation(adjList, 1, 1); printf("\n === low array ===\n "); printArray(low, VertexNum+1); }