摘要:
并查集+set容器 Kruskal#include <stdio.h>#include <string.h>#include <set>using namespace std;const int MAXN = 501;struct E{ int x,y; int weight;};E edge[25001];int father[MAXN];int cmp(const void *d1,const void *d2){ return (*(E*)d1).weight - (*(E*)d2).weight;}void makeSet(int n){ for(i 阅读全文
摘要:
基础 Kruskal#include <iostream>#include <stdio.h>using namespace std;const int MAXN = 101;struct E{ int x,y; int weight;};E edge[MAXN*MAXN/2];int G[MAXN][MAXN];int father[MAXN];int cmp(const void *d1, const void *d2){ return (*(E*)d1).weight - (*(E*)d2).weight;}void makeSet(int n){ for(int 阅读全文
摘要:
读入边权要注意是否比原来的边权小#include <iostream>#include <fstream>#include <string.h>using namespace std;const int MAXN = 1000;int G[MAXN][MAXN];int lowcost[MAXN];int cloest[MAXN];bool used[MAXN];int cost;void PRIM(int n){ int cnt = 0; cost = 0; used[1] = true; for(int i = 2; i <= n; i++){ l 阅读全文
摘要:
最小生成树..#include <iostream>#include <string.h>#include <math.h>#include <iomanip>using namespace std;const int MAXN = 101;struct point { double x,y;};point p[MAXN];double G[MAXN][MAXN];double lowcost[MAXN];int closest[MAXN];bool used[MAXN];double cost;void PRIM(int n){ cost = 阅读全文
摘要:
基础的最小生成树 有的路已经建好了,就把矩阵置0 就可以了//prim MST#include <stdio.h>#include <stdlib.h>#include <string.h>int G[101][101]; bool used[101]; int lowcost[101];int closest[101];int cost;void prim(int n){ cost = 0; used[1] = true; int minj; for(int i = 2; i <= n; i++){ lowcost[i] = G[i][1]; clo 阅读全文
摘要:
并查集 找连通分量 水之#include <stdio.h>int set[1001];int find(int x){ while(set[x] != x) x = set[x]; return x;}void merge(int x,int y){ int fx , fy; fx = find(x); fy = find(y); if(fx != fy){ set[fx] = fy; }}int main(){ int m,n,i,cnt,x,y; while(scanf("%d",&n),n){ for(i = 1; i <= 1000; + 阅读全文