コード例 #1
0
ファイル: 11857.cpp プロジェクト: godely/Problems
int main() {
	while (scanf("%d%d", &n, &m) == 2 && (n+m) > 0) {
		init();
		while (!heap.empty()) heap.pop();
		Rp(i,m) scanf("%d%d%d", &a, &b, &c), heap.pb(mp(c,mp(a,b)));
		int ans = 0, k = 0;
		while (!heap.empty()) {
			pipii aux = heap.top();
			heap.pop();
			if (sameset(aux.S.F,aux.S.S)) continue;
			k++;
			unionset(aux.S.F,aux.S.S);
			ans = aux.F;
			if (k == n-1) break;
		}
		if (k == n-1) printf("%d\n", ans);
		else printf("IMPOSSIBLE\n");
	}
	return 0;
}