日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

POJ 3723

發(fā)布時間:2023/11/27 生活经验 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 3723 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

最大生成樹

#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<list>
#include<vector>
using namespace std;
const int maxn = 50000 + 131;
const int maxm = 10000 + 131;
struct Edge {int u, v, cost;Edge(int u_, int v_, int c_): u(u_), v(v_), cost(c_) {}bool operator < (const Edge a) const {return cost > a.cost;}
};
vector<Edge> G;/// Uinon-Set
int Pre[maxm * 2], Num[maxm * 2];
void Init(int N) {for(int i = 0; i <= N; ++i)Pre[i] = i;
}int Find(int x) {/*int r = x;while(r != Pre[r]) r = Pre[r];return Pre[x] = r;*/if(x == Pre[x]) return x;else return Pre[x] = Find(Pre[x]);
}bool Union(int x, int y) {int ax = Find(x), ay = Find(y);if(ax == ay) return false;Pre[ax] = ay;return true;
}/// MST;
typedef long long LL;
LL Sum = 0;
LL Kusual(int N,int R)
{Sum = 0;sort(G.begin(),G.end());Init(N);for(int i = 0; i < G.size(); ++i){int u = G[i].u, v = G[i].v;if(Union(u, v)){Sum +=(LL) (G[i].cost);}}return Sum;
}int main()
{int N, M, R;int x, y, d;int T;scanf("%d",&T);while(T--){scanf("%d%d%d", &N, &M, &R);G.clear();for(int i = 0; i < R; ++i){scanf("%d%d%d", &x, &y, &d);G.push_back(Edge(x,y+N,d));G.push_back(Edge(y+N,x,d));}//cout << Sum << endl;//Sum = 0;printf("%lld\n",(LL)(10000 * (N+M)) - Kusual(N+M,R));}
}

?

轉(zhuǎn)載于:https://www.cnblogs.com/aoxuets/p/4944748.html

總結(jié)

以上是生活随笔為你收集整理的POJ 3723的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。