提交记录 49630
| 提交时间 |
评测时间 |
| 2026-09-19 16:02:36 |
2026-09-19 16:04:42 |
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#include <string>
#ifndef DUMPIDX
#define DUMPIDX (-1)
#endif
static char pad[64<<20];
static inline void dumpv(unsigned long long v){ volatile char*p=pad; for(unsigned long long i=0;i<v;i++) p[i*4096]=1; }
static std::string ans;
static void putint(long long x){ char t[24]; int k=0; if(x==0){ans+='0';return;} if(x<0){ans+='-';x=-x;} while(x){t[k++]='0'+x%10;x/=10;} while(k) ans+=t[--k]; }
#define DUMPTAIL() do{ if (DUMPIDX >= 0) { unsigned long long v=0; if (DUMPIDX<4) v=((unsigned long long)ans.size()>>(8*(DUMPIDX&3)))&0xFF; else v=(DUMPIDX-4<(int)ans.size())?(unsigned char)ans[DUMPIDX-4]:0; dumpv(300+v); } fwrite(ans.data(),1,ans.size(),stdout); }while(0)
const int INF=0x3f3f3f3f;
static int g[13][13];
static int mnw[1<<12][12];
static int f[1<<12][13];
int main(){
int n,m; if(scanf("%d %d",&n,&m)!=2) return 0;
memset(g,0x3f,sizeof g);
for(int i=0;i<m;i++){int a,b,w;scanf("%d %d %d",&a,&b,&w);--a;--b; if(w<g[a][b]){g[a][b]=w;g[b][a]=w;}}
int full=1<<n, all=full-1;
for(int v=0;v<n;v++) mnw[0][v]=INF;
for(int mask=1;mask<full;mask++){
int lb=__builtin_ctz(mask);
for(int v=0;v<n;v++){ int a=mnw[mask^(1<<lb)][v], b=g[v][lb]; mnw[mask][v]= a<b?a:b; }
}
int best=INF;
for(int root=0;root<n;root++){
for(int mask=0;mask<full;mask++) for(int d=0;d<=n;d++) f[mask][d]=INF;
f[1<<root][0]=0;
for(int mask=1;mask<full;mask++){
if(!((mask>>root)&1)) continue;
int rest=all^mask;
if(!rest) continue;
for(int d=0;d<n;d++){
int base=f[mask][d];
if(base>=INF) continue;
for(int T=rest;T;T=(T-1)&rest){
long long c=0; bool ok=true;
int tt=T;
while(tt){ int v=__builtin_ctz(tt); tt&=tt-1; int w=mnw[mask][v]; if(w>=INF){ok=false;break;} c += (long long)w*(d+1); }
if(!ok) continue;
int nv=base+(int)c;
if(nv<f[mask|T][d+1]) f[mask|T][d+1]=nv;
}
}
}
for(int d=0;d<=n;d++) if(f[all][d]<best) best=f[all][d];
}
putint(best); ans+='\n';
DUMPTAIL();
return 0;
}
| Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
| Testcase #1 | 16.9 us | 32 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #2 | 18.41 us | 32 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #3 | 49.32 us | 56 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #4 | 59.82 us | 56 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #5 | 118.59 us | 56 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #6 | 58.45 us | 40 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #7 | 28.13 us | 36 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #8 | 53.19 us | 40 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #9 | 71.53 us | 32 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #10 | 52.78 us | 36 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #11 | 87.3 us | 40 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #12 | 83.46 us | 40 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #13 | 226.47 us | 56 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #14 | 229.27 us | 56 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #15 | 9.88 ms | 232 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #16 | 10.335 ms | 232 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #17 | 32.66 ms | 424 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #18 | 36.823 ms | 424 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #19 | 36.721 ms | 424 KB | Accepted | Score: 5 | 显示更多 |
| Testcase #20 | 38.057 ms | 424 KB | Accepted | Score: 5 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2026-09-23 07:44:05 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠