#include<iostream>
#include<algorithm>
using namespace std;
int bin[1000];
struct dat
{
int x, y, t;
}d[1000];
bool cmp(dat a, dat b)
{
return a.t < b.t;
};
int findx(int x)
{
while (bin[x - 1] != x)
x = bin[x - 1];
return x;
};
void merge(int x, int y)
{
if (findx(x) != findx(y))
bin[findx(y) - 1] = findx(x);
};
int main()
{
int N, M, x, y, t;
while (cin >> N >> M)
{
for (int i = 0; i < N; i++)
{
bin[i] = i + 1;
cin >> d[i].x >> d[i].y >> d[i].t;
}
dat e[1000];
memcpy(e, d, M * sizeof(dat));
sort(e, e + M, cmp);
int count = 0, max = 0;
for (int i = 0; i < M; i++)
{
if (count == N - 1)
break;
if (findx(e[i].x) != findx(e[i].y))
{
merge(e[i].x, e[i].y);
if (e[i].t > max)
max = e[i].t;
count += 1;
}
}
if (count != N - 1)
{
cout << -1 << endl;
continue;
}
cout << max << endl;
}
}
在自己的编译器上能跑通,但是一直编译错误,请问问题是出在哪了呀