Submission #1846155


Source Code Expand

#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)
#define iter0(i, n) for (int i = 0; i < n; ++i)

const int inf = 1e9;

int n, m, U, M, f[20][1 << 15], h[20][1 << 15], g[20][20], ws[1 << 15];

int dfs(int x, int s);

int dfs2(int x, int s) {
	//printf("!!%d %d\n", x, s);
	assert(s >> x & 1);
	if (s == U) {
		return x == n - 1 ? 0 : -inf;
	}
	int &w = h[x][s];
	if (w != -1) return w;
	w = -inf;
	iter0(i, n) if (!(s >> i & 1) && g[x][i]) {
		w = max(w, g[x][i] + dfs(i, s));
	}
	//if (x == 0 && s == 29)	printf("h[%d][%d]=%d %d\n", x, s, h[x][s], s >> (n - 1) & 1);
	return w;
}
int sum = 0;
int dfs(int x, int s) {
//	printf("!d %d %d\n", x, s);
	int &w = f[x][s];
	if (w != -1) return w;
	w = -inf;
	int t = U - s;
	for (int _t = t; _t; _t = (_t - 1) & t) {
		if (_t >> x & 1) {
			w = max(w, ws[_t] + dfs2(x, s | _t));
		//	if (x == 1 && s == 29) printf("%d %d %d %d %d\n", x, s, _t, sum - dfs2(x, s | _t) - ws[_t], ws[_t]);
		}
	}
//	printf("f[%d][%d]=%d\n", x, s, sum - f[x][s]);
	return w;
}

int main() {
	//freopen("78F.in", "r", stdin);
	memset(f, -1, sizeof(f));
	memset(h, -1, sizeof(h));
	scanf("%d%d", &n, &m);
	M = 1 << n;
	U = M - 1;
	
	iter(i, m) {
		int x, y, c;
		scanf("%d%d%d", &x, &y, &c); --x, --y;
		g[x][y] = g[y][x] = c;
		sum += c;
	}

	iter0(s, M) {
		iter0(i, n) if (s >> i & 1) {
			iter0(j, i) if (s >> j & 1) ws[s] += g[i][j];
		}
		//printf("!%d %d\n", s, ws[s]);
	}

	printf("%d\n", sum - dfs(0, 0));
	return 0;
}

Submission Info

Submission Time
Task F - Mole and Abandoned Mine
User Ketsui
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1617 Byte
Status AC
Exec Time 151 ms
Memory 5376 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:52:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
./Main.cpp:58:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &x, &y, &c); --x, --y;
                              ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 3
AC × 28
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 2 ms 5248 KB
00_example_02.txt AC 2 ms 5248 KB
00_example_03.txt AC 66 ms 5376 KB
01.txt AC 148 ms 5376 KB
02.txt AC 4 ms 5248 KB
03.txt AC 2 ms 5248 KB
04.txt AC 2 ms 5248 KB
05.txt AC 2 ms 5248 KB
06.txt AC 3 ms 5248 KB
07.txt AC 3 ms 5248 KB
08.txt AC 43 ms 5376 KB
09.txt AC 3 ms 5248 KB
10.txt AC 2 ms 5248 KB
11.txt AC 148 ms 5376 KB
12.txt AC 66 ms 5376 KB
13.txt AC 147 ms 5376 KB
14.txt AC 132 ms 5376 KB
15.txt AC 149 ms 5376 KB
16.txt AC 148 ms 5376 KB
17.txt AC 147 ms 5376 KB
18.txt AC 89 ms 5376 KB
19.txt AC 128 ms 5376 KB
20.txt AC 151 ms 5376 KB
21.txt AC 151 ms 5376 KB
22.txt AC 150 ms 5376 KB
23.txt AC 151 ms 5376 KB
24.txt AC 151 ms 5376 KB
25.txt AC 151 ms 5376 KB