1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| #define ll long long 大专栏 【x义x讲坛】10.23模拟赛ss="line">using namespace std;
const int maxN=100005,maxM=400005; int lnk[maxN]; int pre[maxM],tgt[maxM],val[maxM],cnt; void add_E(int u,int v,int c){ pre[++cnt]=lnk[u],tgt[cnt]=v,val[cnt]=c,lnk[u]=cnt; }
int N,M,K; int F[25];
struct node{ int p;ll v; bool operator <(const node b)const{return v>b.v;} }H[500005];int len; void inline putin(node x){H[++len]=x;push_heap(H+1,H+len+1);} node inline putout(){pop_heap(H+1,H+len+1);return H[len--];} ll dis[25][maxN]; bool vis[maxN]; void Dijkstra(int k){ memset(dis[k],63,sizeof(dis[k])); memset(vis,0,sizeof(vis)); dis[k][F[k]]=0; putin((node){F[k],0}); while(len){ node u=putout(); while(len&&vis[u.p]) u=putout(); if(vis[u.p]) break; vis[u.p]=1; for(int e=lnk[u.p];e;e=pre[e]) if(u.v+val[e]<dis[k][tgt[e]]) dis[k][tgt[e]]=u.v+val[e], putin((node){tgt[e],dis[k][tgt[e]]}); } }
bool ANS[1048576]; void Cover(int s){ for(int j=0;j<K;j++)if(s&(1<<j)) if(!ANS[s^(1<<j)]) ANS[s^(1<<j)]=1,Cover(s^(1<<j)); }
const int p=998244353; int qpow(int a,int k){ int ans=1; while(k){ if(k&1) ans=1LL*ans*a%p; a=1LL*a*a%p; k>>=1; } return ans; }
int inline (){ int num=0,neg=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-') neg=-1;c=getchar();} while(c>='0'&&c<='9') num=num*10+c-'0',c=getchar(); return num*neg; }
int main(){ scanf("%d%d%d",&N,&M,&K); for(int i=1;i<=K;i++) scanf("%d",&F[i]); while(M--){ int u=read(),v=read(),c=read(); add_E(u,v,c);add_E(v,u,c); } for(int i=1;i<=K;i++) Dijkstra(i); memset(dis[0],63,sizeof(dis[0])); ll ans=-1; for(int i=1;i<=N;i++){ for(int j=1;j<=K;j++) dis[0][i]=min(dis[0][i],dis[j][i]); ans=max(ans,dis[0][i]); } for(int i=1;i<=N;i++){ int s=0; for(int j=1;j<=K;j++) if(dis[j][i]>ans) s|=(1<<(j-1)); if(!ANS[s]) ANS[s]=1,Cover(s); } int tot=(1<<K); for(int s=0;s<(1<<K);s++) if(ANS[s]) tot--; printf("%dn",1LL*tot*qpow(qpow(2,K),p-2)%p); }
|