結果
| 問題 | No.101 ぐるぐる!あみだくじ! | 
| コンテスト | |
| ユーザー |  kuuso1 | 
| 提出日時 | 2014-12-12 00:01:16 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 31 ms / 5,000 ms | 
| コード長 | 1,948 bytes | 
| コンパイル時間 | 4,787 ms | 
| コンパイル使用メモリ | 107,008 KB | 
| 実行使用メモリ | 18,304 KB | 
| 最終ジャッジ日時 | 2024-06-11 20:50:14 | 
| 合計ジャッジ時間 | 4,237 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 37 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}
class Sol{
	public void Solve(){
		T=new int[N];
		for(int i=0;i<N;i++)T[i]=i;
		for(int i=0;i<Ec;i++){
			swap(ref T[A[i][0]-1],ref T[A[i][1]-1]);
		}
//for(int i=0;i<N;i++)Console.Write("{0} ",T[i]);Console.WriteLine();
		used=new bool[N];
		compo=new int[N];
		int c=0;
		for(int i=0;i<N;i++){
			if(!used[i])dfs(i,++c);
		}
//for(int i=0;i<N;i++)Console.Write("{0} ",compo[i]);Console.WriteLine();
		
		Dictionary<int,int> D=new Dictionary<int,int>();
		for(int i=0;i<N;i++){
			if(!D.ContainsKey(compo[i]))D.Add(compo[i],0);
			D[compo[i]]++;
		}
		
		int ans=1;
		foreach(var k in D.Keys){
//Console.WriteLine("{0}:{1}",k,D[k]);
			ans=lcm(ans,D[k]);
		}
		Console.WriteLine(ans);
		
	}
	
	int[] T;
	bool[] used;
	int[] compo;
	
	void dfs(int now,int c_){
		compo[now]=c_; 
		used[now]=true;
		if(!used[T[now]])dfs(T[now],c_);
	}
	
	int gcd(int a,int b){
		return a==0?b:gcd(b%a,a);
	}
	
	int lcm(int a,int b){
		return a*b/gcd(a,b);
	}
	int N;
	int[][] A;
	int Ec;
	public Sol(){
		N=ri();
		Ec=ri();
		A=new int[Ec][];
		for(int i=0;i<Ec;i++){
			A[i]=ria();
		}
	}
	void swap(ref int a,ref int b){
		int t=a;a=b;b=t;
	}
	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
            
            
            
        