結果
問題 | No.1639 最小通信路 |
ユーザー |
|
提出日時 | 2021-09-23 03:51:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 723 bytes |
コンパイル時間 | 1,482 ms |
コンパイル使用メモリ | 168,304 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 09:23:08 |
合計ジャッジ時間 | 3,268 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> using namespace std; int n, a, b; string c, w; int p[101], r[101]; int find(int x) { if (p[x] == x) return x; return p[x] = find(p[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (r[x] < r[y]) p[x] = y; else { p[y] = x; if (r[x] == r[y]) r[x]++; } } bool same(int x, int y) { return find(x) == find(y); } bool ck() { for (int i = 1; i < n; i++) { if (!same(i, i + 1)) return false; } return true; } int main() { cin >> n; for (int i = 1; i <= n; i++) p[i] = i; for (int i = 0; i < n * (n - 1) / 2; i++) { cin >> a >> b >> c; unite(a, b); if (i > n - 3 && w == "" && ck()) w = c; } cout << w << endl; }