結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー koyumeishikoyumeishi
提出日時 2014-12-05 02:48:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,299 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 72,592 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-02 08:50:52
合計ジャッジ時間 2,964 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//想定誤解法
//最小公倍数を使っていない

#include <iostream>
#include <vector>
#include <map>
#include "assert.h"
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <sstream>

using namespace std;

#define MAX_N 100
#define MAX_K 1000


int dfs(vector< vector<int> > &G, vector<bool> &visit, int pos){
	visit[pos] = true;
	int res = 1;
	for(int i=0; i<G[pos].size(); i++){
		if(visit[ G[pos][i] ] == true) continue;
		res += dfs(G, visit, G[pos][i]);
	}
	return res;
}

long long solve_dfs(const vector<int> &v){
	int n=v.size();
	vector<vector<int> > G(n);
	for(int i=0; i<n; i++){
		G[i].push_back( v[i] );
		G[ v[i] ].push_back( i );
	}

	vector<bool> visit(n,false);
	long long ans = 1;
	for(int i=0; i<n; i++){
		if(visit[i] == true) continue;
		ans *= dfs(G, visit, i);
	}
	return ans;
}

int main(){
	int N;
	cin >> N;
	assert(2<=N && N<=MAX_N);
	
	int K;
	cin >> K;
	assert(0<=K && K<=MAX_K);
	
	
	vector<int> v(N);
	for(int i=0; i<N; i++){
		v[i] = i;
	}
	for(int i=0; i<K; i++){
		int x,y;
		cin >> x >> y;
		assert(1<=x && x<= N);
		assert(1<=y && y<= N);
		assert(x<y);
		assert(x+1 == y);
		
		x--;
		y--;
		
		swap( v[x], v[y] );
	}

	cout << solve_dfs(v) << endl;
	
	return 0;
}
0