Submission #67415085
Source Code Expand
Copy
#include <stdio.h>/* {1,2,3} -> ... -> {3,2,1} */int next_permutation(int arr[], int n) {int target;int i;int temp;for (i = n - 2; i >= 0; i--) {if (arr[i] < arr[i + 1]) break;}if (i < 0) return 0;target = i;for (i = 0; target + i + 1 < n - i - 1; i++) {temp = arr[target + 1 + i];arr[target + 1 + i] = arr[n - 1 - i];arr[n - i - 1] = temp;}for (i = target + 1; i < n; i++) {if (arr[i] > arr[target]) break;
#include <stdio.h> /* {1,2,3} -> ... -> {3,2,1} */ int next_permutation(int arr[], int n) { int target; int i; int temp; for (i = n - 2; i >= 0; i--) { if (arr[i] < arr[i + 1]) break; } if (i < 0) return 0; target = i; for (i = 0; target + i + 1 < n - i - 1; i++) { temp = arr[target + 1 + i]; arr[target + 1 + i] = arr[n - 1 - i]; arr[n - i - 1] = temp; } for (i = target + 1; i < n; i++) { if (arr[i] > arr[target]) break; } temp = arr[i]; arr[i] = arr[target]; arr[target] = temp; return 1; } int N, M; char edges[10][10]; int main(void) { int i, j, g; int ans = 9999; if (scanf("%d%d", &N, &M) != 2) return 1; for (i = 0; i < M; i++) { int A, B; if (scanf("%d%d", &A, &B) != 2) return 1; if (A < B) edges[A][B] = 1; else edges[B][A] = 1; } for (g = 0; g < (1 << (N - 1)); g++) { int groupA[10], groupB[10], acnt = 0, bcnt = 0; for (i = 0; i < N; i++) { if ((g >> i) & 1) groupB[bcnt++] = i + 1; else groupA[acnt++] = i + 1; } if (acnt < 3 || (bcnt < 3 && bcnt != 0)) continue; do { int groupBp[10]; for (i = 0; i < bcnt; i++) groupBp[i] = groupB[i]; do { char edges_target[10][10] = {{0}}; int score = 0; for (i = 0; i < acnt; i++) { int x = groupA[i], y = groupA[(i + 1) % acnt]; if (x < y) edges_target[x][y] = 1; else edges_target[y][x] = 1; } for (i = 0; i < bcnt; i++) { int x = groupBp[i], y = groupBp[(i + 1) % bcnt]; if (x < y) edges_target[x][y] = 1; else edges_target[y][x] = 1; } for (i = 1; i < N; i++) { for (j = i + 1; j <= N; j++) { if (edges[i][j] != edges_target[i][j]) score++; } } if (score < ans) ans = score; } while (next_permutation(groupBp + 1, bcnt - 1)); } while (next_permutation(groupA + 1, acnt - 1)); } printf("%d\n", ans); return 0; } /* 頂点数2で次数を2にしようとすると、多重辺にするしかない。 よって、目標のグラフの連結成分の頂点数は3以上。 N <= 8 なので、頂点数3以上のグループは高々2個しかできない。 */
Submission Info
Submission Time | |
---|---|
Task | D - Make 2-Regular Graph |
User | mikecat |
Language | C (gcc 12.2.0) |
Score | 425 |
Code Size | 2143 Byte |
Status | AC |
Exec Time | 2 ms |
Memory | 1756 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 425 / 425 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample00.txt, sample01.txt, sample02.txt, sample03.txt |
All | sample00.txt, sample01.txt, sample02.txt, sample03.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt, testcase37.txt, testcase38.txt, testcase39.txt, testcase40.txt, testcase41.txt, testcase42.txt, testcase43.txt, testcase44.txt, testcase45.txt, testcase46.txt, testcase47.txt, testcase48.txt, testcase49.txt, testcase50.txt, testcase51.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample00.txt | AC | 1 ms | 1732 KiB |
sample01.txt | AC | 1 ms | 1720 KiB |
sample02.txt | AC | 1 ms | 1724 KiB |
sample03.txt | AC | 2 ms | 1588 KiB |
testcase00.txt | AC | 0 ms | 1616 KiB |
testcase01.txt | AC | 1 ms | 1620 KiB |
testcase02.txt | AC | 0 ms | 1660 KiB |
testcase03.txt | AC | 0 ms | 1588 KiB |
testcase04.txt | AC | 2 ms | 1624 KiB |
testcase05.txt | AC | 1 ms | 1604 KiB |
testcase06.txt | AC | 1 ms | 1728 KiB |
testcase07.txt | AC | 2 ms | 1596 KiB |
testcase08.txt | AC | 1 ms | 1744 KiB |
testcase09.txt | AC | 1 ms | 1736 KiB |
testcase10.txt | AC | 2 ms | 1628 KiB |
testcase11.txt | AC | 0 ms | 1644 KiB |
testcase12.txt | AC | 1 ms | 1628 KiB |
testcase13.txt | AC | 0 ms | 1628 KiB |
testcase14.txt | AC | 1 ms | 1640 KiB |
testcase15.txt | AC | 2 ms | 1636 KiB |
testcase16.txt | AC | 2 ms | 1744 KiB |
testcase17.txt | AC | 1 ms | 1744 KiB |
testcase18.txt | AC | 1 ms | 1648 KiB |
testcase19.txt | AC | 2 ms | 1628 KiB |
testcase20.txt | AC | 2 ms | 1656 KiB |
testcase21.txt | AC | 1 ms | 1656 KiB |
testcase22.txt | AC | 1 ms | 1600 KiB |
testcase23.txt | AC | 1 ms | 1748 KiB |
testcase24.txt | AC | 1 ms | 1708 KiB |
testcase25.txt | AC | 2 ms | 1720 KiB |
testcase26.txt | AC | 2 ms | 1580 KiB |
testcase27.txt | AC | 2 ms | 1728 KiB |
testcase28.txt | AC | 2 ms | 1628 KiB |
testcase29.txt | AC | 1 ms | 1736 KiB |
testcase30.txt | AC | 2 ms | 1632 KiB |
testcase31.txt | AC | 1 ms | 1720 KiB |
testcase32.txt | AC | 2 ms | 1732 KiB |
testcase33.txt | AC | 2 ms | 1604 KiB |
testcase34.txt | AC | 2 ms | 1752 KiB |
testcase35.txt | AC | 2 ms | 1624 KiB |
testcase36.txt | AC | 0 ms | 1576 KiB |
testcase37.txt | AC | 2 ms | 1584 KiB |
testcase38.txt | AC | 1 ms | 1756 KiB |
testcase39.txt | AC | 2 ms | 1596 KiB |
testcase40.txt | AC | 0 ms | 1580 KiB |
testcase41.txt | AC | 2 ms | 1636 KiB |
testcase42.txt | AC | 1 ms | 1648 KiB |
testcase43.txt | AC | 2 ms | 1644 KiB |
testcase44.txt | AC | 1 ms | 1592 KiB |
testcase45.txt | AC | 2 ms | 1752 KiB |
testcase46.txt | AC | 1 ms | 1728 KiB |
testcase47.txt | AC | 2 ms | 1704 KiB |
testcase48.txt | AC | 1 ms | 1732 KiB |
testcase49.txt | AC | 2 ms | 1712 KiB |
testcase50.txt | AC | 1 ms | 1752 KiB |
testcase51.txt | AC | 2 ms | 1580 KiB |