题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 310, M = 8010;
int n, m;
int p[N];
struct Edge{
int a, b, c;
bool operator<(const Edge& W)const
{
return c < W.c;
}
}e[M];
int find(int a)
{
if (p[a] != a) p[a] = find(p[a]);
return p[a];
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++) p[i] = i;
for(int i = 0; i < m; i ++)
{
int a, b, c;
cin >> a >> b >>c;
e[i] = {a, b, c};
}
sort(e, e + m);
int res = 0;
for (int i = 0; i < m; i ++)
{
int a = find(e[i].a), b = find(e[i].b), w = e[i].c;
if (a != b)
{
p[a] = b;
res = w;
}
}
cout << n - 1 << " " << res;
return 0;
}
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla