結果

問題 No.488 四角関係
ユーザー startcppstartcpp
提出日時 2017-02-24 22:56:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 958 bytes
コンパイル時間 464 ms
コンパイル使用メモリ 52,592 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 23:38:04
合計ジャッジ時間 1,556 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#define rep(i, l, r) for(i = l; i < r; i++)
using namespace std;

int n;
bool is_connect[50][50] = {false};

bool check(int a, int b, int c, int d) {
	int i, j;
	int id[4] = {a, b, c, d};
	bool used[4] = {false};
	int now = 0;
	
	used[0] = true;
	rep(i, 0, 3) {
		rep(j, 0, 4) {
			if (used[j] || !is_connect[id[now]][id[j]]) continue;
			used[j] = true;
			now = j;
			break;
		}
		if (j == 4) return false;
	}
	if (!is_connect[id[now]][id[0]]) return false;
	
	rep(i, 0, 4) {
		int cnt = 0;
		rep(j, 0, 4) {
			if (i == j) continue;
			if (is_connect[id[i]][id[j]]) cnt++;
		}
		if (cnt != 2) return false;
	}
	
	return true;
}

int main() {
	int m, a, b;
	int i, j, k, l;
	
	cin >> n >> m;
	rep(i, 0, m) {
		cin >> a >> b;
		is_connect[a][b] = true;
		is_connect[b][a] = true;
	}
	
	int ans = 0;
	rep(i, 0, n)
		rep(j, i + 1, n)
			rep(k, j + 1, n)
				rep(l, k + 1, n)
					ans += check(i, j, k, l);
	cout << ans << endl;
	return 0;
}
0