def lscan; gets.split.map(&:to_i); end n = gets.to_i # class Unionfind { # public: # vector 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