{"id":6192,"date":"2024-08-16T12:01:01","date_gmt":"2024-08-16T04:01:01","guid":{"rendered":""},"modified":"2024-08-16T12:01:01","modified_gmt":"2024-08-16T04:01:01","slug":"\u6700\u77ed\u8deffloyd\u7b97\u6cd5_\u5965\u672c\u6d77\u59c6\u4fe1\u53f7\u4e0e\u7cfb\u7edf\u7b2c\u4e8c\u7248\u7b54\u6848","status":"publish","type":"post","link":"https:\/\/mushiming.com\/6192.html","title":{"rendered":"\u6700\u77ed\u8deffloyd\u7b97\u6cd5_\u5965\u672c\u6d77\u59c6\u4fe1\u53f7\u4e0e\u7cfb\u7edf\u7b2c\u4e8c\u7248\u7b54\u6848"},"content":{"rendered":"

\u5962\u4f88\u7684\u65c5\u884c<\/h2>\n

Time Limit: 14000\/7000 MS (Java\/Others)    Memory Limit: \/ K (Java\/Others)
Total Submission(s): 561    Accepted Submission(s): 109
<\/span><\/strong><\/span>
\n

\n
<\/p>\n

\n Problem Description\n<\/div>\n
\n \u9ad8\u73a9\u5c0fQ\u4e0d\u4ec5\u559c\u6b22\u73a9\u5bfb\u5b9d\u6e38\u620f\uff0c\u8fd8\u559c\u6b22\u4e00\u6b3e\u5347\u7ea7\u517b\u6210\u7c7b\u6e38\u620f\u3002\u5728\u8fd9\u4e2a\u6e38\u620f\u7684\u4e16\u754c\u5730\u56fe\u4e2d\u4e00\u5171\u6709
\n <\/span>
\n n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u4e2a\u57ce\u9547\uff0c\u7f16\u53f7\u4f9d\u6b21\u4e3a
\n <\/span>
\n 1<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u5230
\n <\/span>
\n n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u3002 <\/p>\n

\u8fd9\u4e9b\u57ce\u9547\u4e4b\u95f4\u6709
\n <\/span>
\n m<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u6761\u5355\u5411\u9053\u8def\uff0c\u7b2c
\n <\/span>
\n i<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span> \u6761\u5355\u9879\u9053\u8def\u5305\u542b\u56db\u4e2a\u53c2\u6570
\n <\/span>
\n u<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>,<\/span>v<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>,<\/span>a<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>,<\/span>b<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\uff0c\u8868\u793a\u4e00\u6761\u4ece
\n <\/span>
\n u<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u53f7\u57ce\u9547\u51fa\u53d1\uff0c\u5728
\n <\/span>
\n v<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u53f7\u57ce\u9547\u7ed3\u675f\u7684\u5355\u5411\u9053\u8def\uff0c\u56e0\u4e3a\u662f\u5355\u5411\u9053\u8def\uff0c\u8fd9\u4e0d\u610f\u5473\u7740\u5c0fQ\u53ef\u4ee5\u4ece
\n <\/span>
\n v<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u6cbf\u7740\u8be5\u9053\u8def\u8d70\u5230
\n <\/span>
\n u<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u3002\u5c0fQ\u7684\u521d\u59cb\u7b49\u7ea7
\n <\/span>
\n l<\/span>e<\/span>v<\/span>e<\/span>l<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u4e3a
\n <\/span>
\n 1<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\uff0c\u6bcf\u5f53\u8bd5\u56fe\u7ecf\u8fc7\u4e00\u6761\u9053\u8def\u65f6\uff0c\u9700\u8981\u652f\u4ed8
\n <\/span>
\n c<\/span>o<\/span>s<\/span>t<\/span>=<\/span>log<\/span><\/span><\/span>2<\/span><\/span><\/span><\/span><\/span><\/span>l<\/span>e<\/span>v<\/span>e<\/span>l<\/span>+<\/span>a<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>l<\/span>e<\/span>v<\/span>e<\/span>l<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u70b9\u79ef\u5206\uff0c\u5e76\u4e14\u7ecf\u8fc7\u8be5\u9053\u8def\u540e\uff0c\u5c0fQ\u7684\u7b49\u7ea7\u4f1a\u63d0\u5347
\n <\/span>
\n a<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u7ea7\uff0c\u5230\u8fbe
\n <\/span>
\n l<\/span>e<\/span>v<\/span>e<\/span>l<\/span>+<\/span>a<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u7ea7\u3002\u4f46\u662f\u6bcf\u6761\u9053\u8def\u90fd\u4f1a\u5728\u4e00\u5b9a\u610f\u4e49\u4e0a\u6b67\u89c6\u4f4e\u6d88\u8d39\u73a9\u5bb6\uff0c\u51c6\u786e\u5730\u8bf4\uff0c\u5982\u679c\u8be5\u6b21\u6240\u9700\u79ef\u5206
\n <\/span>
\n c<\/span>o<\/span>s<\/span>t<\/span><<\/span>b<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\uff0c\u90a3\u4e48\u5c0fQ\u4e0d\u80fd\u7ecf\u8fc7\u8be5\u6b21\u9053\u8def\uff0c\u4e5f\u4e0d\u80fd\u63d0\u5347\u76f8\u5e94\u7684\u7b49\u7ea7\u3002 <\/p>\n

\u6ce8\u610f\uff1a\u672c\u6e38\u620f\u4e2d\u7b49\u7ea7\u4e3a\u6b63\u6574\u6570\uff0c\u4f46\u662f\u79ef\u5206\u53ef\u4ee5\u662f\u4efb\u610f\u5b9e\u6570\u3002 <\/p>\n

\u5c0fQ\u4f4d\u4e8e
\n <\/span>
\n 1<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u53f7\u57ce\u9547\uff0c\u7b49\u7ea7\u4e3a
\n <\/span>
\n 1<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\uff0c\u73b0\u5728\u4e3a\u4e86\u505a\u4efb\u52a1\u8981\u5230
\n <\/span>
\n n<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u53f7\u57ce\u9547\u53bb\u3002\u8fd9\u5c06\u4f1a\u662f\u4e00\u6b21\u5962\u4f88\u7684\u65c5\u884c\uff0c\u8bf7\u5199\u4e00\u4e2a\u7a0b\u5e8f\u5e2e\u52a9\u5c0fQ\u627e\u5230\u9700\u8981\u652f\u4ed8\u7684\u603b\u79ef\u5206\u6700\u5c11\u7684\u4e00\u6761\u8def\u7ebf\uff0c\u6216\u5224\u65ad\u8fd9\u662f\u4e0d\u53ef\u80fd\u7684\u3002\n<\/div>\n

\n  \n<\/div>\n


<\/p>\n

\n Input\n<\/div>\n
\n \u7b2c\u4e00\u884c\u5305\u542b\u4e00\u4e2a\u6b63\u6574\u6570
\n <\/span>
\n T<\/span><\/span>(<\/span>1<\/span>\u2264<\/span>T<\/span><\/span>\u2264<\/span>30<\/span>)<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\uff0c\u8868\u793a\u6d4b\u8bd5\u6570\u636e\u7684\u7ec4\u6570\u3002 <\/p>\n

\u6bcf\u7ec4\u6570\u636e\u7b2c\u4e00\u884c\u5305\u542b\u4e24\u4e2a\u6574\u6570
\n <\/span>
\n n<\/span>,<\/span>m<\/span>(<\/span>2<\/span>\u2264<\/span>n<\/span>\u2264<\/span><\/span>,<\/span>1<\/span>\u2264<\/span>m<\/span>\u2264<\/span><\/span>)<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\uff0c\u8868\u793a\u57ce\u9547\u6570\u548c\u9053\u8def\u6570\u3002 <\/p>\n

\u63a5\u4e0b\u6765
\n <\/span>
\n m<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u884c\uff0c\u6bcf\u884c\u56db\u4e2a\u6574\u6570
\n <\/span>
\n u<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>,<\/span>v<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>,<\/span>a<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>,<\/span>b<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>(<\/span>1<\/span>\u2264<\/span>u<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>,<\/span>v<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>\u2264<\/span>n<\/span>,<\/span>u<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>\u2260<\/span>v<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>,<\/span>0<\/span>\u2264<\/span>a<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>\u2264<\/span>10<\/span><\/span><\/span>9<\/span><\/span><\/span><\/span><\/span>,<\/span>0<\/span>\u2264<\/span>b<\/span><\/span><\/span>i<\/span><\/span><\/span><\/span><\/span>\u2264<\/span>60<\/span>)<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\uff0c\u5206\u522b\u8868\u793a\u6bcf\u6761\u5355\u5411\u9053\u8def\u3002\n<\/div>\n

\n  \n<\/div>\n


<\/p>\n

\n Output\n<\/div>\n
\n \u5bf9\u4e8e\u6bcf\u7ec4\u6570\u636e\uff0c\u8f93\u51fa\u4e00\u884c\u4e00\u4e2a\u6574\u6570\uff0c\u5373\u6700\u5c11\u6240\u9700\u7684\u603b\u79ef\u5206\u7684\u6574\u6570\u90e8\u5206\uff0c\u5982\uff1a
\n <\/span>
\n 4.9999<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u8f93\u51fa
\n <\/span>
\n 4<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\uff0c
\n <\/span>
\n 1.0<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u8f93\u51fa
\n <\/span>
\n 1<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u3002\u82e5\u4e0d\u5b58\u5728\u5408\u6cd5\u8def\u7ebf\u8bf7\u8f93\u51fa
\n <\/span>
\n \u2212<\/span>1<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span>\u3002\n<\/div>\n
\n  \n<\/div>\n


<\/p>\n

\n Sample Input\n<\/div>\n
\n
<\/pre>\n
\n 13 31 2 3 22 3 1 61 3 5 0\n <\/div>\n<\/div>\n
\n  \n<\/div>\n


<\/p>\n

\n Sample Output\n<\/div>\n
\n
<\/pre>\n
\n 2\n <\/div>\n<\/div>\n
\n  \n<\/div>\n


<\/p>\n

\n Source\n<\/div>\n
\n \"\u5b57\u8282\u8df3\u52a8\u676f\"2018\u4e2d\u56fd\u5927\u5b66\u751f\u7a0b\u5e8f\u8bbe\u8ba1\u7ade\u8d5b-\u5973\u751f\u4e13\u573a\n<\/div>\n
\n  \n<\/div>\n


<\/p>\n

\n Recommend\n<\/div>\n
\n liuyiding\n<\/div>\n

<\/p>\n<\/p>\n

    \u9898\u610f\uff1a\u5c0fQ\u57281\u60f3\u53bbn, \u7ed9\u4f60n\u4e2a\u57ce\u5e02m\u6761\u8def\u5f84\uff0c\u7136\u540e\u662f\u5355\u5411\u8def\u5f84\uff0ca\u4ee3\u8868\u901a\u8fc7\u8fd9\u6761\u8def\u5c0fQ\u63d0\u5347\u7684\u7b49\u7ea7\uff0cb\u4ee3\u8868\u7ecf\u8fc7\u8fd9\u6761\u8def\u9700\u8981\u8017\u8d39\u6700\u5c0f\u7684\u8fc7\u8def\u8d39\u3002<\/p>\n

   log2[(a+level)\/level]>=b\uff0c\u53ef\u4ee5\u4e24\u8fb9\u53d6log2 \u53d8\u6210a\/level+1>=2^b   \u8f6c\u5316\u6210  a\/level >=2^b-1;<\/span><\/p>\n

\u4e5f\u5c31\u53d1\u73b0\u82b1\u8d39\u8ddf2\u7684\u6b21\u65b9-1\u6709\u5173\uff0c\u5c31\u5f00\u59cb\u5efa\u56fe\uff0c2^b-1\u63d0\u524d\u5904\u7406\u597d\u3002<\/span><\/p>\n

\u5361spfa\uff0c\u7528dijkstra+\u5806\u4f18\u5316\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u70b9\u9700\u8981\u5224\u65ada\/level \u548c 2^b-1\u7684\u5173\u7cfb\uff0c\u5982\u679c\u5c0f\u4e8e\u5219\u4e0d\u80fd\u901a\u8fc7\uff0cdis[u]\u5b58\u7684\u662flevel<\/span><\/p>\n

   
<\/span><\/p>\n

#include<bits\/stdc++.h> using namespace std; const long long INF=1e18; long long dis[]; int head[]; int vis[]; struct node{ int u; int v; long long a; long long b; int next; }no[]; struct Node{ int pos; long long dis; friend bool operator<(const Node&a,const Node&b) { return a.dis>b.dis; } }; int cnt; int n,m; void add(int u,int v,long long a,long long b) { no[cnt].u=u; no[cnt].v=v; no[cnt].a=a; no[cnt].b=b; no[cnt].next=head[u]; head[u]=cnt++; } void dj() { for(int i=0;i<=n;i++) { vis[i]=0; dis[i]=INF; } priority_queue<Node>que; Node p,q; p.pos=1; p.dis=1ll; que.push(p); dis[1]=1ll; while(!que.empty()) { p=que.top(); que.pop(); int u=p.pos; if(vis[u]) continue; vis[u]=1; for(int i=head[u];i!=-1;i=no[i].next) { int v=no[i].v; long long cost=no[i].a; if((long long )cost\/dis[u] < no[i].b)\/\/ continue; if(dis[v] > dis[u]+cost) { dis[v]=dis[u]+cost; q.pos=v; q.dis=dis[v]; que.push(q); } } } if(dis[n]==INF) printf(\"-1\\n\"); else printf(\"%d\\n\",(int)(log2(dis[n]*1.0))); } int main() { int t; scanf(\"%d\",&t); while(t--) { cnt=0; memset(head,-1,sizeof(head)); scanf(\"%d%d\",&n,&m); int u,v; long long a,b; for(int i=0;i<m;i++) { scanf(\"%d%d%lld%lld\",&u,&v,&a,&b); add(u,v,a,((long long)1<<b)-1); } dj(); } return 0; } <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u6700\u77ed\u8deffloyd\u7b97\u6cd5_\u5965\u672c\u6d77\u59c6\u4fe1\u53f7\u4e0e\u7cfb\u7edf\u7b2c\u4e8c\u7248\u7b54\u6848\u5962\u4f88\u7684\u65c5\u884cTimeLimit:14000\/7000MS(Java\/Others)MemoryLimit:\/K(Java\/Others)T...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6192"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=6192"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6192\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=6192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=6192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=6192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}