Submission #2119291
Source Code Expand
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first
const int MX = 15;
const int MM = 1000000007;
int N, M;
int G[MX][MX];
ll T[1<<MX][MX];
int main()
{
int N, M, a, b, c;
scanf("%d%d", &N, &M);
for(int i = 1; i <= M; i++){
scanf("%d%d%d", &a, &b, &c); a--, b--;
G[a][b] = G[b][a] = c;
}
for(int i = 0; i < 1<<N; i++){
for(int j = 0; j < N; j++) T[i][j] = 1e18;
}
for(int i = 1; i < 1<<N; i+=2) T[i][0] = 0;
for(int i = 1; i < 1<<N; i+=2){
for(int k = i; k; k = (k-1)&i){
if( k&1 ) continue;
int b = i^k;
ll mn = 1e18, tot = 0;
for(int p = 0; p < N; p++){
if( ~b&1<<p ) continue;
for(int q = 0; q < N; q++){
if( k&1<<q ) tot += G[p][q];
}
}
for(int l = 0; l < N; l++){
if( ~b&1<<l) continue;
for(int j = 0; j < N; j++){
if(k&1<<j && G[l][j]) T[i][j] = min(T[i][j], T[b][l] + tot - G[l][j]);
}
}
}
}
printf("%lld\n", T[(1<<N)-1][N-1]);
}
Submission Info
Submission Time |
|
Task |
F - Mole and Abandoned Mine |
User |
zigui |
Language |
C++14 (GCC 5.4.1) |
Score |
900 |
Code Size |
2039 Byte |
Status |
AC |
Exec Time |
2667 ms |
Memory |
4096 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:62: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:64:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &a, &b, &c); a--, b--;
^
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 |
2408 ms |
4096 KB |
01.txt |
AC |
2634 ms |
4096 KB |
02.txt |
AC |
21 ms |
512 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 |
3 ms |
256 KB |
07.txt |
AC |
3 ms |
256 KB |
08.txt |
AC |
767 ms |
2176 KB |
09.txt |
AC |
3 ms |
256 KB |
10.txt |
AC |
1 ms |
256 KB |
11.txt |
AC |
2636 ms |
4096 KB |
12.txt |
AC |
2405 ms |
4096 KB |
13.txt |
AC |
2621 ms |
4096 KB |
14.txt |
AC |
2663 ms |
4096 KB |
15.txt |
AC |
2637 ms |
4096 KB |
16.txt |
AC |
2623 ms |
4096 KB |
17.txt |
AC |
2667 ms |
4096 KB |
18.txt |
AC |
2385 ms |
4096 KB |
19.txt |
AC |
2517 ms |
4096 KB |
20.txt |
AC |
2532 ms |
4096 KB |
21.txt |
AC |
2398 ms |
4096 KB |
22.txt |
AC |
2398 ms |
4096 KB |
23.txt |
AC |
2398 ms |
4096 KB |
24.txt |
AC |
2398 ms |
4096 KB |
25.txt |
AC |
2399 ms |
4096 KB |