Submission #1847262
Source Code Expand
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset>
#include <string>
#include <cmath>
#include <set>
#include <map>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
#define ev g[i].y
#define eps 1e-10
#define d(x) (1 << x - 1)
using namespace std;
typedef long long ll;
typedef double db;
const int N = 16, M = 1 << N, mod = 1000000007;
int n, m, sn, a[N][N], g[M], f[N][M], sum;
int main()
{
scanf ("%d%d", &n, &m);
Rep(i, 1, m) {
int x, y, z;
scanf ("%d%d%d", &x, &y, &z);
a[x][y] = a[y][x] = z;
sum += z;
}
sn = (1 << n) - 1;
Rep(p, 1, sn) {
Rep(j, 1, n) if (d(j) & p) {
Rep(k, j + 1, n) if (d(k) & p) {
g[p] += a[j][k];
}
}
if (!(d(1) & p)) continue ;
f[1][p] = g[p];
Rep(j, 1, n) if (d(j) & p) {
for(int q = p & (p - 1); q; q = (q - 1) & p) if ((d(1) & q) && !(d(j) & q)) {
Rep(k, 1, n) if ((d(k) & q) && a[j][k] && (k == 1 || f[k][q])) {
f[j][p] = max(f[j][p], f[k][q] + a[j][k] + g[p - q]);
}
}
}
}
// cout << f[n][sn]<<endl;
printf("%d\n", sum - f[n][sn]);
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Mole and Abandoned Mine |
User |
hzt1 |
Language |
C++14 (GCC 5.4.1) |
Score |
900 |
Code Size |
1278 Byte |
Status |
AC |
Exec Time |
1442 ms |
Memory |
3456 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:25:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d", &n, &m);
^
./Main.cpp:28:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d%d", &x, &y, &z);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
900 / 900 |
Status |
|
|
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 |
1 ms |
256 KB |
00_example_02.txt |
AC |
1 ms |
256 KB |
00_example_03.txt |
AC |
1367 ms |
3328 KB |
01.txt |
AC |
1432 ms |
3328 KB |
02.txt |
AC |
12 ms |
2432 KB |
03.txt |
AC |
1 ms |
256 KB |
04.txt |
AC |
1 ms |
256 KB |
05.txt |
AC |
1 ms |
256 KB |
06.txt |
AC |
2 ms |
2304 KB |
07.txt |
AC |
2 ms |
2304 KB |
08.txt |
AC |
429 ms |
2816 KB |
09.txt |
AC |
2 ms |
2304 KB |
10.txt |
AC |
1 ms |
256 KB |
11.txt |
AC |
1426 ms |
3328 KB |
12.txt |
AC |
1367 ms |
3328 KB |
13.txt |
AC |
1430 ms |
3328 KB |
14.txt |
AC |
1442 ms |
3328 KB |
15.txt |
AC |
1427 ms |
3328 KB |
16.txt |
AC |
1415 ms |
3328 KB |
17.txt |
AC |
1421 ms |
3328 KB |
18.txt |
AC |
1340 ms |
3328 KB |
19.txt |
AC |
1401 ms |
3328 KB |
20.txt |
AC |
1413 ms |
3456 KB |
21.txt |
AC |
1369 ms |
3328 KB |
22.txt |
AC |
1369 ms |
3328 KB |
23.txt |
AC |
1372 ms |
3328 KB |
24.txt |
AC |
1369 ms |
3328 KB |
25.txt |
AC |
1369 ms |
3328 KB |