結果
問題 | No.2418 情報通だよ!Nafmoくん |
ユーザー |
![]() |
提出日時 | 2023-08-14 23:58:52 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 323 ms / 2,000 ms |
コード長 | 404 bytes |
コンパイル時間 | 267 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 20,224 KB |
最終ジャッジ日時 | 2024-11-14 12:24:55 |
合計ジャッジ時間 | 6,112 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
コンパイルメッセージ
Syntax OK
ソースコード
def fut(ut,no) if ut[no]==no then return no else ut[no]=fut(ut,ut[no]) return ut[no] end end n,m=gets.split(" ").map{|e| e.to_i} ut=[0] utc=[0] 1.upto(2*n){|i| ut<<i utc<<1 } m.times{ a,b=gets.split(" ").map{|e| e.to_i} atop=fut(ut,a) btop=fut(ut,b) next if atop==btop ut[atop]=btop utc[btop]+=utc[atop] } ans=0 1.upto(2*n){|i| itop=fut(ut,i) ans+=utc[itop]%2 utc[itop]=0 } puts ans/2