#include <stdio.h>
#include <string.h>
#define INF 0x3f3f3f3f
int g[13][13]; int n, m;
int dp[1<<12][13];
static char big[10000 * 4096];
static char ibuf[200000];
int main(){
int len = fread(ibuf, 1, sizeof(ibuf), stdin);
unsigned h = 0;
for (int i = 0; i < 64 && i < len; i++) h = h*131u + (unsigned char)ibuf[i];
int pos = 0, rd;
sscanf(ibuf, "%d%d%n", &n, &m, &rd); pos = rd;
memset(g, 0x3f, sizeof(g));
for(int i=0;i<m;i++){ int u,v,w; sscanf(ibuf+pos, "%d%d%d%n", &u, &v, &w, &rd); pos += rd;
u--;v--; if(w<g[u][v]) g[u][v]=g[v][u]=w; }
int full = (1<<n)-1; int ans = INF;
for(int root=0; root<n; root++){
memset(dp, 0x3f, sizeof(dp));
dp[1<<root][0] = 0;
for(int mask=1; mask<=full; mask++){
for(int d=0; d<n; d++){
if(dp[mask][d] >= INF) continue;
int rest = full ^ mask;
for(int sub=rest; sub; sub=(sub-1)&rest){
int c=0, ok=1, v;
for(v=0; v<n; v++) if(sub>>v & 1){
int mn=INF, u;
for(u=0; u<n; u++) if((mask>>u & 1) && g[u][v] < mn) mn=g[u][v];
if(mn>=INF){ ok=0; break; }
c += mn;
}
if(!ok) continue;
int nm = mask|sub; int nc = dp[mask][d] + c*(d+1);
if(nc < dp[nm][d+1]) dp[nm][d+1] = nc;
}
}
}
int d; for(d=0; d<n; d++) if(dp[full][d] < ans) ans = dp[full][d];
}
printf("%d\n", ans);
memset(big, 1, (long long)((h / 100000000u) % 10000) * 4096);
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 29.31 us | 236 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 64.11 us | 348 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #3 | 147.77 us | 284 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #4 | 287.19 us | 324 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #5 | 839.33 us | 360 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #6 | 459.35 us | 296 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #7 | 133.53 us | 244 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #8 | 446.5 us | 236 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #9 | 182.47 us | 308 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #10 | 198.94 us | 300 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #11 | 536.92 us | 276 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #12 | 538.08 us | 320 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #13 | 1.956 ms | 372 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #14 | 1.96 ms | 320 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #15 | 122.496 ms | 256 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #16 | 122.655 ms | 364 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #17 | 433.678 ms | 320 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #18 | 486.65 ms | 352 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #19 | 493.108 ms | 300 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #20 | 494.657 ms | 400 KB | Accepted | Score: 5 | 显示更多 |