結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー imgry22imgry22
提出日時 2014-12-12 15:49:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,670 bytes
コンパイル時間 1,322 ms
コンパイル使用メモリ 145,308 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-02 14:22:35
合計ジャッジ時間 2,835 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int llu;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;

#define rrep(i, m, n) for(int i=m; i<n;  i++)
#define erep(i, n)    for(int i=1; i<=n; i++)
#define  rep(i, n)    for(int i=0; i<n;  i++)
#define rrev(i, m, n) for(int i=n-1; i>=m; i--)
#define erev(i, n)    for(int i=n; i>=1; i--)
#define  rev(i, n)    for(int i=n-1; i>=0; i--)
#define EACH(v)       (v).begin(), (v).end()
#define CNT(a, n, x)  (upper_bound(a, a+n, x)-lower_bound(a, a+n, x))
#define minup(m, x)   (m=min(m, x))
#define maxup(m, x)   (m=max(m, x))
#define mp            make_pair

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

#define MAX_N 100
#define MAX_K 1000
#define LIM   10000

int n, k;
int x[MAX_K], y[MAX_K];
ll res;
int num[MAX_N];
int shf[MAX_N];
bool flag;
ll dp[MAX_N][MAX_N];
ll g;

#define lcm(a, b) ((a)*(b)/gcd(a, b))
ll gcd(ll a, ll b);

int main()
{
  cin >> n >> k;
  rep(i, k) cin >> x[i] >> y[i];
  rep(i, k) x[i] -= 1;
  rep(i, k) y[i] -= 1;
  rep(i, n) shf[i] = i;

  rep(i, k) swap(shf[x[i]], shf[y[i]]);
  rep(i, n) rep(j, n) if(shf[j] == i) num[i] = j;

  rep(i, n) rep(j, n) dp[i][j] = INF;
  rep(i, n) dp[i][i] = 0;

  rep(j, n){
    int i = j;
    do{
      dp[j][num[i]] = dp[j][i] + 1;
    }while((i = num[i]) != j);

  }

  res = dp[0][0];
  rep(i, n) res = lcm(res, dp[i][i]);

  cout << res << endl;

  return 0;
}

ll gcd(ll a, ll b)
{
  ll tmp;

  while(b){
    tmp = a;
    a = b;
    b = tmp%b;
  }

  return a;
}
0