Submission #1103560


Source Code Expand

//#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>

using namespace std;

//ifstream cin("tema.in");
//ofstream cout("tema.out");

const int MAXN = 8;

int n, answer = 0, v[1 + MAXN];
bool edge[1 + MAXN][1 + MAXN], seen[1 + MAXN];

void Backtracking(int x) {
    if (x == n + 1) {
        answer++;
        return;
    }
    for (int i = 1; i <= n; i++)
        if (!seen[i] && edge[v[x - 1]][i]) {
            v[x] = i;
            seen[i] = true;
            Backtracking(x + 1);
            seen[i] = false;
        }
}

int main() {
    int m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        edge[a][b] = edge[b][a] = true;
    }
    v[1] = 1;
    seen[1] = 1;
    Backtracking(2);
    cout << answer << "\n";
    return 0;
}

Submission Info

Submission Time
Task C - One-stroke Path
User fanache99
Language C++14 (GCC 5.4.1)
Score 300
Code Size 895 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