//想定解法 dfs //1.あみだくじを1回だけシミュレートして置換先を決定し、置換先同士を繋げたグラフにする // この時ループしている部分は一つの環になる。 //2.グラフをdfsして部分のループの長さを得る //3.ループの長さの最小公倍数が答え //n<=100のため最大ケースは232792560 = 16*9*5*7*11*13*17*19となる。多分。オーバーフローはしないはず #include #include #include #include "assert.h" #include #include #include #include using namespace std; #define MAX_N 100 #define MAX_K 1000 long long gcd(long long a, long long b){ if(b==0) return a; return gcd(b, a%b); } long long lcm(long long a, long long b){ if(a > &G, vector &visit, int pos){ visit[pos] = true; int res = 1; for(int i=0; i &v){ int n=v.size(); vector > G(n); for(int i=0; i visit(n,false); int ans = 1; for(int i=0; i> N; assert(2<=N && N<=MAX_N); int K; cin >> K; assert(0<=K && K<=MAX_K); vector v(N); for(int i=0; i> x >> y; assert(1<=x && x<= N); assert(1<=y && y<= N); assert(x