結果
問題 | No.1563 Same Degree |
ユーザー |
|
提出日時 | 2021-06-26 13:02:50 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 314 ms / 2,000 ms |
コード長 | 4,355 bytes |
コンパイル時間 | 95 ms |
コンパイル使用メモリ | 7,936 KB |
実行使用メモリ | 13,568 KB |
最終ジャッジ日時 | 2024-06-25 10:08:00 |
合計ジャッジ時間 | 4,423 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 15 |
コンパイルメッセージ
Syntax OK
ソースコード
def solven, m = intsdegree = [0] * nm.times dou, v = int1sdegree[u] += 1degree[v] += 1endset = Set.newdegree.each do |x|return true if set.include?(x)set << xendfalseenddef maint = intt.times doputs solve ? "Yes" : "No"endendrequire "set"DEBUG = trueMOD = 10**9+7YESNO = %w(No Yes)INF = 10**9def int; gets.to_s.to_i enddef ints; gets.to_s.split.map { |s| s.to_i } enddef int1s; gets.to_s.split.map { |s| s.to_i - 1 } enddef intss(n); Array.new(n) { ints }; enddef float; gets.to_s.to_f enddef floats; gets.to_s.split.map { |s| s.to_f } enddef array_of(&convert); gets.to_s.split.map(&convert) enddef string; gets.to_s.chomp enddef rep(n, &b); Array.new(n, &b) enddef yes; puts YESNO[1] enddef no; puts YESNO[0] enddef yesno t; puts YESNO[t] enddef zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } enddef max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max enddef min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min enddef minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax enddef gcd(*xs); xs.inject(0, :gcd) enddef matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } enddef debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x enddef debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid enddef if_debug; yield if DEBUG endmodule Booleandef coerce(other); [other, to_i] enddef +@; to_i enddef to_int; to_i enddef *(other); to_i * other endendclass TrueClassinclude Booleandef to_i; 1 endendclass FalseClassinclude Booleandef to_i; 0 endendclass Integerdef div_ceil(y); (self + y - 1) / y enddef mod_inv(mod = MOD); pow(mod-2, mod) enddef mod_div(y, mod = MOD); self * mod_inv(y, mod) % mod enddef factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } enddef popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: fasterdef bitbrute(&block); (1<<self).times(&block) enddef nCr(r); x = 1; (1..r).each { |i| x *= self + 1 - i; x /= i }; x; enddef each_divisor; return Enumerator.new { |y| each_divisor { |k| y << k } } unless block_given?; k = 1; while k * k < self; if self % k == 0; yieldk; yield self / k end; k += 1; end; yield k if k * k == self enddef divisors; each_divisor.to_a endendclass Rangedef end_open; exclude_end? ? self.end : self.end + 1 enddef end_close; exclude_end? ? self.end - 1 : self.end enddef upper_bound; ac, wa = self.begin, self.end_open; while wa - ac > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ?ac : nil enddef lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ?ac : nil enddef shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } };enddef widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i,j] } } enddef pairs; Enumerator.new { |y| l, r = self.begin, self.end_open; i = l; while i < r - 1; j = i + 1; while j < r; y.yield(i, j); j += 1 end; i += 1end } endendclass Arraydef power(&block); (0 ... 1 << size).each(&block) enddef sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i+= 1 end while i < n; a.push(*other[j..-1]) if j < m; a enddef upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac enddef lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac enddef cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a enddef cumdiff(range); self[range.end_open] - self[range.begin]; endendmodule Enumerabledef sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } enddef cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys endendmain