Submission #4047414
Source Code Expand
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<cmath> #include<map> #include<iomanip> #include<queue> #include<numeric> //完コピ。DFS要勉強 using namespace std; typedef long long LL; LL gcd(LL a, LL b) { LL r; while ((r = a % b) != 0) { a = b; b = r; } return b; } LL lcm(LL a, LL b) { return (a / gcd(a, b) * b); } bool graph[8][8]; int dfs(int v, int n, bool visited[8]) { bool all_visited = true; for (int i = 0; i < n; i++) { if (visited[i] == false) { all_visited = false; } } if (all_visited) { return 1; } int ret = 0; for (int i = 0; i < n; i++) { if (graph[v][i] == false) { continue; } if (visited[i]) { continue; } visited[i] = true; ret += dfs(i, n, visited); visited[i] = false; } return ret; } int main(void) { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; graph[a - 1][b - 1] = graph[b - 1][a - 1] = true; } bool visited[8]; for (int i = 0; i < n; i++) { visited[i] = false; } visited[0] = true; cout << dfs(0, n, visited) << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - One-stroke Path |
User | kuroku_969 |
Language | C++14 (GCC 5.4.1) |
Score | 300 |
Code Size | 1181 Byte |
Status | AC |
Exec Time | 1 ms |
Memory | 256 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
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 |