結果
| 問題 | No.101 ぐるぐる!あみだくじ! | 
| コンテスト | |
| ユーザー |  kosakkun | 
| 提出日時 | 2016-12-13 18:03:46 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 5,000 ms | 
| コード長 | 1,471 bytes | 
| コンパイル時間 | 981 ms | 
| コンパイル使用メモリ | 95,824 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-30 01:13:58 | 
| 合計ジャッジ時間 | 2,192 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 37 | 
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
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){
    return a*b/gcd(a,b);
}
int main(){
    
    int N,K; cin>>N>>K;
    vector<int> X(K),Y(K);
    REP(i,K)cin>>X[i]>>Y[i];
    
    int cnt[101]={};
    for(int i=1;i<=N;i++){
        int now=i;
        do{
            REP(i,K){
                if(X[i]==now){
                    now=Y[i];
                }else if(Y[i]==now){
                    now=X[i];
                }
            }
            cnt[i]++;
        }while(now!=i);
    }
    
    ll ans=1;
    for(int i=1;i<=N;i++){
        ans=lcm(ans,(ll)cnt[i]);
    }
    
    cout<<ans<<endl;
    
    return 0;
}
            
            
            
        