結果

問題 No.488 四角関係
ユーザー naimonon77naimonon77
提出日時 2017-02-25 11:11:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 258 ms / 5,000 ms
コード長 3,099 bytes
コンパイル時間 1,964 ms
コンパイル使用メモリ 183,408 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 07:59:04
合計ジャッジ時間 3,523 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#include <random>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for(int i=a;\
            c>0?i<b:\
            i>b;\
            i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep) {
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

template<class InputIterator>
int sum(InputIterator begin, InputIterator end) {
	return accumulate(begin, end, 0ll);
}

int H = 50;
int W = 50;

bool ng(int y, int x) {
	return y < 0 || H <= y || x < 0 || W <= x;
}

int N, M;
vector<int> connect_[100];
bool connect_matrix[100][100];
bool visited[100];
vector<int> visited_v;
set<vector<int>> set1;

int dfs(int start, int pre, int now, int depth) {
	if (depth == 3) {
		if (visited_v.size() != 4) abort();
		auto tmp_vec = visited_v;
		sort(all(tmp_vec));
		if (set1.count(tmp_vec) == 1) return 0;
		if (connect_matrix[start][now]) {
			rep(i, 2) {
				if (connect_matrix[visited_v[i]][visited_v[i + 2]]) {
					return 0;
				}
			}
			if (test) {
				rep(i, 4) {
					cout << visited_v[i] << " ";
				}
				cout << endl;
			}
			set1.insert(tmp_vec);

			return 1;

		}
		return 0;
	}

	int res = 0;

	rep(i, connect_[now].size()) {
		int next = connect_[now][i];
		if (visited[next]) continue;
		visited[next] = true;
		visited_v.push_back(next);
		res += dfs(start, now, next, depth + 1);
		visited_v.pop_back();
		visited[next] = false;
	}
	return res;
}

void solve() {
	set1.clear();
	cin >> N >> M;
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		connect_matrix[a][b] = true;
		connect_matrix[b][a] = true;

		connect_[a].push_back(b);
		connect_[b].push_back(a);
	}
	int res = 0;
	rep(i, N) {
		visited[i] = true;
		visited_v.push_back(i);
		res += dfs(i, i, i, 0);
		visited_v.pop_back();
		visited[i] = false;
	}
	cout << res << endl;
}


signed main() {
	srand(time(NULL));
	int T = 100;
	cout << fixed << setprecision(15);
	rep(i, T) {
		char s[MAX];
		if (scanf("%s", s) == EOF) break;
		int n = strlen(s);
		for (int i = n - 1; i > -1; i--) {
			ungetc(s[i], stdin);
		}
		solve();
	}
	return 0;
}
0