結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー 👑 horiesinitihoriesiniti
提出日時 2023-08-14 23:58:52
言語 Ruby
(3.3.0)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 404 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 19,328 KB
最終ジャッジ日時 2024-05-02 12:04:53
合計ジャッジ時間 7,099 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
12,416 KB
testcase_01 AC 97 ms
12,160 KB
testcase_02 AC 93 ms
12,416 KB
testcase_03 AC 330 ms
16,128 KB
testcase_04 AC 157 ms
15,744 KB
testcase_05 AC 259 ms
13,952 KB
testcase_06 AC 260 ms
16,512 KB
testcase_07 AC 276 ms
13,824 KB
testcase_08 AC 265 ms
19,328 KB
testcase_09 AC 324 ms
14,848 KB
testcase_10 AC 333 ms
16,768 KB
testcase_11 AC 300 ms
15,744 KB
testcase_12 AC 233 ms
14,848 KB
testcase_13 AC 161 ms
13,312 KB
testcase_14 AC 220 ms
14,592 KB
testcase_15 AC 235 ms
12,288 KB
testcase_16 AC 359 ms
16,000 KB
testcase_17 AC 172 ms
12,544 KB
testcase_18 AC 224 ms
16,256 KB
testcase_19 AC 144 ms
16,128 KB
testcase_20 AC 243 ms
12,288 KB
testcase_21 AC 176 ms
13,824 KB
testcase_22 AC 190 ms
13,056 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
0