結果
| 問題 | No.101 ぐるぐる!あみだくじ! | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-02-02 15:38:02 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 40 ms / 5,000 ms | 
| コード長 | 472 bytes | 
| コンパイル時間 | 108 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 10,880 KB | 
| 最終ジャッジ日時 | 2024-06-11 09:27:22 | 
| 合計ジャッジ時間 | 2,690 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 37 | 
ソースコード
import sys
import math
def input(): return sys.stdin.readline().rstrip()
def main():
    N = int(input())
    K = int(input())
    *A, = range(N)
    for i in range(K):
        X, Y = map(int, input().split())
        A[X-1], A[Y-1] = A[Y-1], A[X-1]
    ans = 1
    for i in range(N):
        c = 1
        j = A[i]
        while j != i:
            c += 1
            j = A[j]
        ans = math.lcm(ans, c)
    print(ans)
if __name__ == '__main__':
    main()
            
            
            
        