Submission #1608594


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define INF 2000000000
#define LINF 9000000000000000000

typedef long long ll;
typedef pair<int, int> P;

int n, m;
bool d[8][8];
bool visited[8];

int dfs(int v) {
	bool all = true;

	for (int i = 0; i < n; i++) {
		if (!visited[i]) all = false;
	}
	if (all) return 1;

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (!d[v][i]) continue;
		if (visited[i]) continue;
		visited[i] = true;
		cnt += dfs(i);
		visited[i] = false;
	}

	return cnt;
}

int main(){
	cin.tie(0);
  ios::sync_with_stdio(false);

	for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) d[i][j] = false;
	for (int i = 0; i < 8; i++) visited[i] = false;

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		d[a][b] = d[b][a] = true;
	}

	visited[0] = true;
	int ans = dfs(0);
	cout << ans << endl;

	return 0;
}

Submission Info

Submission Time
Task C - One-stroke Path
User moko_freedom
Language C++14 (GCC 5.4.1)
Score 300
Code Size 927 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 15
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All sample_01.txt, sample_02.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
subtask_1_01.txt AC 1 ms 256 KB
subtask_1_02.txt AC 1 ms 256 KB
subtask_1_03.txt AC 1 ms 256 KB
subtask_1_04.txt AC 1 ms 256 KB
subtask_1_05.txt AC 1 ms 256 KB
subtask_1_06.txt AC 1 ms 256 KB
subtask_1_07.txt AC 1 ms 256 KB
subtask_1_08.txt AC 1 ms 256 KB
subtask_1_09.txt AC 1 ms 256 KB
subtask_1_10.txt AC 1 ms 256 KB
subtask_1_11.txt AC 1 ms 256 KB
subtask_1_12.txt AC 1 ms 256 KB
subtask_1_13.txt AC 1 ms 256 KB