This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, m, par[10], a[10], b[10], c[10], res;
void f(int x) {
c[x] = 1;
for (int i = 1; i <= n; i++) {
if (par[i] == x) {
f(i);
}
}
}
void go(int x) {
if (x == n + 1) {
for (int i = 1; i <= n; i++) c[i] = 0;
f(1);
bool ok = 1;
for (int i = 1; i <= n; i++) if (c[i] == 0) ok = 0;
for (int i = 1; i <= m; i++) if (!(par[a[i]] == b[i] || par[b[i]] == a[i])) ok = 0;
if (ok) res++;
return;
}
if (x == 1) {
par[x] = 0;
go(x + 1);
}
else {
for (int i = 1; i <= n; i++) {
if (i == x) continue;
par[x] = i;
go(x + 1);
}
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) scanf("%d%d", &a[i], &b[i]);
res = 0;
go(1);
printf("%d", res);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |