結果
| 問題 |
No.101 ぐるぐる!あみだくじ!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-04 11:33:00 |
| 言語 | Python2 (2.7.18) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 464 bytes |
| コンパイル時間 | 56 ms |
| コンパイル使用メモリ | 6,912 KB |
| 実行使用メモリ | 8,192 KB |
| 最終ジャッジ日時 | 2024-11-21 15:33:56 |
| 合計ジャッジ時間 | 2,422 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 WA * 29 |
ソースコード
from fractions import gcd
N = input()
K = input()
xy = [map(int, raw_input().split()) for _ in xrange(K)]
A = range(N)
for x, y in xy:
A[x-1], A[y-1] = A[y-1], A[x-1]
uf = []
for i in xrange(N):
for u in uf:
if i in u or A[i] in u:
u.add(i)
u.add(A[i])
break
else:
uf.append(set([i, A[i]]))
uf = map(len, uf)
lcm = uf[0]
for i in xrange(1, len(uf)):
lcm = lcm*uf[i]/gcd(lcm, uf[i])
print lcm