結果
| 問題 |
No.101 ぐるぐる!あみだくじ!
|
| コンテスト | |
| ユーザー |
h_noson
|
| 提出日時 | 2016-04-01 00:14:38 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 917 bytes |
| コンパイル時間 | 453 ms |
| コンパイル使用メモリ | 59,932 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-02 08:42:09 |
| 合計ジャッジ時間 | 1,512 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 WA * 3 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000
typedef long long ll;
int c[101];
int s[101];
int dfs(int x, int d) {
if (c[x] > 0)
return c[x];
else if (c[x] == -1) {
c[x] = d;
return d;
}
else {
c[x] = -1;
return c[x] = dfs(s[x],d+1);
}
}
int gcd(int a, int b) {
return b == 0 ? a : gcd(b,a%b);
}
int lcm(int a, int b) {
return a * b / gcd(a,b);
}
int main() {
int i, n, k, ans;
cin >> n >> k;
REP (i,1,n+1) s[i] = i;
rep (i,k) {
int x, y;
cin >> x >> y;
swap(s[x],s[y]);
}
REP (i,1,n+1) dfs(i,0);
ans = 1;
REP (i,1,n+1) ans = lcm(ans,c[i]);
cout << ans << endl;
return 0;
}
h_noson