結果

問題 No.1639 最小通信路
ユーザー maimai
提出日時 2021-08-06 22:00:21
言語 Ruby
(3.3.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 11,852 KB
実行使用メモリ 16,464 KB
最終ジャッジ日時 2023-10-17 03:21:48
合計ジャッジ時間 4,178 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
16,036 KB
testcase_01 AC 66 ms
16,036 KB
testcase_02 AC 68 ms
16,036 KB
testcase_03 AC 67 ms
16,144 KB
testcase_04 AC 82 ms
16,464 KB
testcase_05 AC 67 ms
16,036 KB
testcase_06 AC 67 ms
16,036 KB
testcase_07 AC 69 ms
16,036 KB
testcase_08 AC 67 ms
16,036 KB
testcase_09 AC 67 ms
16,036 KB
testcase_10 AC 68 ms
16,036 KB
testcase_11 AC 70 ms
16,036 KB
testcase_12 AC 67 ms
16,036 KB
testcase_13 AC 67 ms
16,036 KB
testcase_14 AC 66 ms
16,036 KB
testcase_15 AC 65 ms
16,036 KB
testcase_16 AC 66 ms
16,036 KB
testcase_17 AC 66 ms
16,036 KB
testcase_18 AC 65 ms
16,036 KB
testcase_19 AC 66 ms
16,036 KB
testcase_20 AC 67 ms
16,032 KB
testcase_21 AC 65 ms
16,036 KB
testcase_22 AC 66 ms
16,036 KB
testcase_23 AC 67 ms
16,036 KB
testcase_24 AC 68 ms
16,036 KB
testcase_25 AC 67 ms
16,036 KB
testcase_26 AC 67 ms
16,036 KB
testcase_27 AC 66 ms
16,036 KB
testcase_28 AC 66 ms
16,036 KB
testcase_29 AC 66 ms
16,036 KB
testcase_30 AC 68 ms
16,144 KB
testcase_31 AC 66 ms
16,040 KB
testcase_32 AC 66 ms
16,036 KB
testcase_33 AC 66 ms
16,036 KB
testcase_34 AC 66 ms
16,144 KB
testcase_35 AC 68 ms
16,144 KB
testcase_36 AC 68 ms
16,144 KB
testcase_37 AC 69 ms
16,136 KB
testcase_38 AC 70 ms
16,036 KB
testcase_39 AC 69 ms
16,036 KB
testcase_40 AC 69 ms
16,032 KB
testcase_41 AC 68 ms
16,036 KB
testcase_42 AC 71 ms
16,144 KB
testcase_43 AC 69 ms
16,036 KB
testcase_44 AC 70 ms
16,036 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def lscan; gets.split.map(&:to_i); end

n = gets.to_i

# class Unionfind {
# public:
#   vector<int> data;
#   explicit Unionfind(int size) : data(size, -1) {}
#   bool connect(int x, int y) {
#     x = root(x);
#     y = root(y);
#     if (x != y) {
#       if (data[y] < data[x])
#         swap(x, y);
#       data[x] += data[y];
#       data[y] = (int)x;
#     }
#     return x != y;
#   }
#   inline bool same(int x, int y) { return root(x) == root(y); }
#   inline int root(int x) { return (int)(data[x] < 0 ? x : data[x] = root(data[x])); }
#   inline int size(int x) { return -data[root(x)]; }
# };

uf = [-1]*n

root = lambda do |x|
  uf[x] < 0 ? x : (uf[x] = root.call(uf[x]))
end
conn = lambda do |x, y|
  x = root.call(x)
  y = root.call(y)
  if x != y
    x,y = y,x if uf[y] < uf[x]
    uf[x] += uf[y]
    uf[y] = x
  end
  x != y
end

max = 0
(n*(n-1)/2).times do
  a,b,c = lscan
  a -= 1
  b -= 1
  max = [c, max].max if conn.call(a,b)
  if -uf[root.call(a)] == n
    p max
    exit
  end
end
0