Submission #19676

#TimeUsernameProblemLanguageResultExecution timeMemory
19676hongjun7트리 (kriii4_X)C++98
9 / 100
97 ms1084 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...