int main() { int i, j, k, t = 0; while (1) { scanf("%d", &n); if (n == 0) break; for (i = 1; i <= n; i++) scanf("%d%d", &stones[i].x, &stones[i].y); k = 0; for (i = 1; i <= n; i++) for (j = i+1; j <= n; j++) { paths[k].u = i; paths[k].v = j; paths[k].w = (stones[i].x-stones[j].x)*(stones[i].x-stones[j].x) + (stones[i].y-stones[j].y)*(stones[i].y-stones[j].y); k++; } edge_num = k; kruskal(); t++; printf("Scenario #%d\nFrog Distance = %.3f\n\n", t, sqrt(get_result())); } return 0; }
int main() { int i,k; double temp; char aa[24],bb[24]; memset(father,-1,sizeof(father)); memset(rank,0,sizeof(rank)); scanf("%lf",&total); scanf("%d",&n); for(i=0;i<n;i++)scanf("%s",str[i]); qsort(str,n,sizeof(str[0]),cmp); scanf("%d",&m); for(k=0;k<m;k++) { scanf("%s%s%lf",aa,bb,&temp); nodes[k].i=find(aa); nodes[k].j=find(bb); nodes[k].value=temp; } qsort(nodes,m,sizeof(nodes[0]),cmp1); if(kruskal())printf("Need %.1lf miles of cable\n",ans); else printf("Not enough cable\n"); return 0; }
int main() { int n,k,cost; int i,j; char a[2],b[2]; while(1) { scanf("%d",&n); if(0 == n) { break; } gIndex=0; for(i=0;i<n-1;++i) { scanf("%s%d",a,&k); for(j=0;j<k;++j) { scanf("%s%d",b,&cost); graph[gIndex].va=a[0]-'A';//将字符A映射到0,依次往后推 graph[gIndex].vb=b[0]-'A'; graph[gIndex].cost=cost; ++gIndex; } } printf("%d\n",kruskal()); } return 0; }
int main() { Polyhedron P; Point a(1,0,0); Point b(0,1,0); Point c(0,0,1); Point d(0,0,0); P.make_tetrahedron(a,b,c,d); // associate indices to the vertices using the "id()" field of the vertex. vertex_iterator vb, ve; int index = 0; // boost::tie assigns the first and second element of the std::pair // returned by boost::vertices to the variables vit and ve for(boost::tie(vb,ve)=vertices(P); vb!=ve; ++vb ){ vertex_descriptor vd = *vb; vd->id() = index++; } kruskal(P); return 0; }
int main() { int n_edge, n_v, res, i, j, w, t; scanf("%d", &t); while(t--) { memset(flag, '0', sizeof(flag)); scanf("%d", &n_v); n_edge = 0; for(i = 1;i <= n_v; i++) { for(j = 1;j <= n_v; j++) { scanf("%d", &w); if(i != j && flag[i][j] == '0') { flag[i][j] = '1'; flag[j][i] = '1'; e[n_edge].u = i; e[n_edge].v = j; e[n_edge].w = w; n_edge++; } } } res = kruskal(e, n_edge, n_v); printf("%d\n", res); } return 0; }
std::vector< LineSegment* > Voronoi::spanningTree( enum KruskalType type /*, keepOutMask:BitmapData = null */) { std::vector< Edge* > edges = selectNonIntersectingEdges( /*keepOutMask,*/_edges ); std::vector< LineSegment* > segments = delaunayLinesForEdges( edges ); return kruskal( segments, type ); }
int main(int argc,char** argv){ char c; bool complet=true; char* tvalue=NULL; int taille=15; bool BoolAffiche=true; bool resultat=true; while((c=getopt(argc,argv,"oncpsrt:"))!=-1){ switch(c) { case 'c': break; case 'r': resultat=false; break; case 'p': complet=false; break; case 't': tvalue=optarg; break; case 's': BoolAffiche=false; break; case '?': printf("usage: -s desactiver l'affichage -c:graphe complet -p:graphe partielle -t:taille a specifier\n"); default: abort(); } } if(tvalue!=NULL) taille=atoi(tvalue); srand(time(NULL)); Matrix m; if(complet==true) m=grapheComplet(taille); else m=graphePartiel(taille); if(BoolAffiche==true){ affichage(m); printf("\n"); } Matrix ARPM=kruskal(m,resultat); if(BoolAffiche==true){ printf("\n"); affichage(ARPM); printf("\n"); } deleteMatrix(m); deleteMatrix(ARPM); return 0; }
void main() { int prev[MAX] = {0}; int dist[MAX] = {0}; MGraph* pG; // 创造一个图 pG = createGraph();; // 打印图 //printGraph(*pG); // 深度优先遍历 //DFSTraverse(*pG); // 广度优先遍历 //BFSTraverse(*pG); // prim算法生成最小生成树 prim(*pG, 0); // kruskal算法生成最小生成树 kruskal(*pG); // dijkstra算法获取"第4个顶点"到其它各个顶点的最短距离 // dijkstra(*pG, 3, prev, dist); system("pause"); }
int main(void) { int node_num, edge_num; double ans; struct Graph graph; while (scanf("%d %d", &node_num, &edge_num) != EOF) { initGraph(&graph, node_num); input(&graph, edge_num); printf("Boruvka:\n"); ans = boruvka(&graph); printf("the MST weigths %2.1f\n", ans); clearChoosedEdge(&graph); printf("kruskal:\n"); ans = kruskal(&graph); printf("the MST weights %.2lf\n", ans); clearChoosedEdge(&graph); printf("prim:\n"); ans = prim(&graph); printf("the MST weights %.2lf\n", ans); deleteEdge(&graph); } return 0; }
int main(int argc, char *argv[]) { char * filename = "DEFAYE_Johan.txt"; int * edge_MST; unsigned int number_vertices = 0; unsigned int number_edges = 0; //get the number of vertices and the number of edges read_get_sizes(filename, &number_vertices, &number_edges); node nodes[number_vertices]; edge edges[number_edges]; //instanciate the arrays by reading the file read_create_arrays(filename, &nodes, &edges, number_vertices, number_edges); //finding the index of each edge which belong to the Minimum Spaning Tree edge_MST = kruskal(edges, number_vertices, number_edges); //create the graphe with Latex create_latex_file(edges, nodes, number_vertices, number_edges); //create the MST with Latex create_latex_file_MST(edges, nodes, edge_MST, number_vertices, number_edges); return 0; }
int main() { int n, m; scanf("%d %d", &n, &m); std::vector<Point2D64F> points(n); for (int i = 0; i < n; ++i) { scanf("%lf %lf", &points[i].x, &points[i].y); } WeightedDirectedGraphAsEdgeList<double> graph(n); for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { graph.AddEdge(i, j, Distance(points[i], points[j])); } } while (m--) { int u, v; scanf("%d %d", &u, &v); --u; --v; graph.AddEdge(u, v, 0.0); } Kruskal<WeightedDirectedGraphAsEdgeList<double> > kruskal(&graph); kruskal.Compute(); printf("%.2f\n", kruskal.TotalWeight()); return 0; }
int main(int argc, char **argv) { while(scanf("%d", &n) != EOF) { init(); kruskal(); } }
int g_main(int argc, char ** argv) { graph_t * g = adj_list_read<char,weight_t>(cin, UNDINET); cout << g << endl; kruskal(g); graph_destroy(g); return 0; }
main() { int n,m; Edge p[100001]; scanf("%d%d",&n,&m); int i; for(i=0;i<m;i++)scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].w); printf("%d",kruskal(p,n,m)); }
int main() { int a[100][100],n; printf("enter the number of vertices\n"); scanf("%d",&n); AdjacencyMatrix(a,n); kruskal(a,n); return 0; }
int main(void) { int i, count = 0; int case_number; int edges_number, vertices_number; int path[MAX_EDGES]; struct edge edges[MAX_EDGES]; /* How many case will be calculate. */ scanf("%d", &case_number); while (case_number--) { /* How many edges and vertices. */ scanf("%d %d", &vertices_number, &edges_number); /* for each edges. */ for (i = 0; i < edges_number; i++) { /* Get edges start, end and weight. */ scanf("%d %d %d", &edges[i].x, &edges[i].y, &edges[i].weight); } /* Sort edges by weight. */ if (edges_number > 0) { qsort(edges, edges_number - 1, sizeof(struct edge), edge_weight_compare); } int first_way_cost, second_way_cost; /* Initialize first_way_cost and second_way_cost to INF. */ first_way_cost = second_way_cost = INF; /* Get spanning tree cost and modify path. */ first_way_cost = kruskal(edges, edges_number, vertices_number, path); /* Path number is vertices_number - 1 */ for (i = 1; i < vertices_number; i++) { int temp = smst(edges, edges_number, vertices_number, path, path[i]); second_way_cost = min(second_way_cost, temp); } /* Only one way, multiple way, or no way. */ if (first_way_cost == INF) printf("Case #%d : No way\n", ++count); else if (second_way_cost == INF) printf("Case #%d : No second way\n", ++count); else printf("Case #%d : %d\n", ++count, second_way_cost); } return 0; }
int main(int argc, char *argv[]) { if ( argc != 3 ) { printf("Voce deve fornecer um arquivo de entrada e um de saida\n"); return 0; } Grafo *grafo = leArq(argv[1]); grafo = kruskal(grafo); salvaArqGrafo(argv[2], grafo); printf("Fim de execucao\n"); return 0; }
int main() { while(scanf("%d %d", &n, &m) != EOF) { init(); if(check() == 0) printf("poor snoopy\n"); else { printf("%0.2lf\n", kruskal()); } } return 0; }
int main() { while(scanf("%d%d",&n,&m)!=EOF){ int i; for(i=0;i<m;i++) scanf("%d%d%d",&nodes[i].x,&nodes[i].y,&nodes[i].len); qsort(nodes,m,sizeof(nodes[0]),cmp); printf("%d\n%d\n",kruskal(),n-1); for(i=0;i<n-1;i++) printf("%d %d\n",xx[i],yy[i]); } return 0; }
int main() { FILE * f = fopen("matrix.txt","r"); readFromAdjMatrix(f); printAdjMatrix(); bfs(0); dfs(0); dfsRecurs(0); prim(0); kruskal(); dijkstra(0); bellman_ford(0); return 0; }
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() { Polyhedron P; Point a(1,0,0); Point b(0,1,0); Point c(0,0,1); Point d(0,0,0); P.make_tetrahedron(a,b,c,d); kruskal(P); return 0; }
void main() { Graph graph; Graph tree; createdGraph(&graph); initTree(&tree); printf("普里姆算法树中顶点加入的顺序:\n"); prim(&graph,&tree); printf("\n"); initTree(&tree); printf("克鲁斯卡尔算法树中边加入的顺序:\n"); kruskal(&graph,&tree); printf("\n"); }
int main() { int a,b,i,n,m; scanf("%d%d",&n,&m); for (i=0;i<m;i++) { scanf("%d%d%d",&a,&b,&edge[i].weigh); rank[i]=i; edge[i].a=a-1; edge[i].b=b-1; } printf("%d\n",kruskal(n,m)); return 0; }
int main() { for (int i = 0; i < max_v; i++) { p[i] = i; } add_edge(0, 2, 5); add_edge(0, 3, 5); add_edge(3, 4, 5); add_edge(0, 1, 1); add_edge(1, 2, 1); add_edge(2, 3, 1); add_edge(4, 1, 1); printf("%d", kruskal()); return 0; }
int main() { int t; si(t); int i,j; while(t--) { ans=0; int size=0; int n; si(n); vert[0].x=0; vert[0].y=0; parent[0]=-1; for(i=1;i<=n;i++) { int a,b; si(a); si(b); vert[i].x=a; vert[i].y=b; parent[i]=-1; } size=0; for(i=0;i<=n;i++) { for(j=i;j<=n;j++) { if(j!=i) { edge[size].st=i; edge[size].en=j; edge[size].w=abs(vert[i].x-vert[j].x)+abs(vert[i].y-vert[j].y); size++; } } } qsort(edge,size,sizeof(ed),cmp); /*for(i=0;i<size;i++) { printf("%d%d%d\n",vert[edge[i].st].x,vert[edge[i].en].x,edge[i].w); }*/ kruskal(size); printf("%lld\n",ans); } return 0; }
int main() { scanf("%d %d",&n,&m); int i; for(i=0;i<m;i++) scanf("%d %d %d",&edges[i].u,&edges[i].v,&edges[i].w); qsort(edges,m,sizeof(edge),cmpfunc); /*for(i=0;i<m;i++) { printf("%d %d %d\n",edges[i].u,edges[i].v,edges[i].w); }*/ kruskal(); printf("%lld\n",ans); return 0; }
void main() { Graph* pG; // 自定义"图"(输入矩阵队列) //pG = create_graph(); // 采用已有的"图" pG = create_example_graph(); //print_graph(*pG); // 打印图 //DFSTraverse(*pG); // 深度优先遍历 //BFS(*pG); // 广度优先遍历 //prim(*pG, 0); // prim算法生成最小生成树 kruskal(*pG); // kruskal算法生成最小生成树 }
int main() { int r[10],i,cost[10][10],j,n; printf("enter the no of vertices"); scanf("%d",&n); for(i=1;i<=n;i++) r[i]=i; printf("enter the cost adjacency matrix"); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) scanf("%d",&cost[i][j]); } kruskal(n,cost,r); return 0; }
int main() { MGraph G; createGraph(G); Edge *edges = (Edge*)malloc(G.arcnum*sizeof(Edge)); kruskal(G,edges); printf("最小生成树包含的边的信息如下:\n"); int i; for(i=0; i<G.arcnum; i++) { if(edges[i].isIn == 1) { printf("%d->%d:%d\n",edges[i].u+1,edges[i].v+1,edges[i].weight); } } return 1; }