ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#202554 | #540. 免费 | augury | 100 | 4591ms | 67824kb | C++11 | 1.4kb | 2024-02-16 09:47:14 | 2024-02-16 12:33:22 |
answer
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int ans=0;bool op=0;char ch=getchar();
while(ch<'0'||'9'<ch){if(ch=='-')op=1;ch=getchar();}
while('0'<=ch&&ch<='9'){ans=(ans<<1)+(ans<<3)+(ch^48);ch=getchar();}
if(op)return -ans;
return ans;
}
const int maxn=2e6+5;
struct node{
int u,val;
bool operator<(const node&x)const{return val>x.val;}
};
struct edge{
int nxt,to,val;
}e[maxn*4];
int n,m,S,T,K;
priority_queue<node>q;
int vis[maxn],dis[maxn];
int fst[maxn],ce;
void add(int u,int v,int w){e[++ce]=(edge){fst[u],v,w},fst[u]=ce;}
int getid(int x,int y){
return x+y*n;
}
void dij(){
q.push((node){S,0});
for(int i=1;i<=(K+1)*n;i++){
dis[i]=1e9;
}
dis[S]=0;
while(!q.empty()){
int u=q.top().u;
q.pop();
if(vis[u]){
continue;
}
vis[u]=1;
for(int i=fst[u];i;i=e[i].nxt){
int now=e[i].to;
if(dis[now]>dis[u]+e[i].val){
dis[now]=dis[u]+e[i].val;
q.push((node){now,dis[now]});
}
}
}
}
signed main(){
n=read(),m=read(),S=read(),T=read(),K=read();
for(int i=1;i<=m;i++){
int u=read(),v=read(),w=read();
for(int j=0;j<K;j++){
add(getid(u,j),getid(v,j+1),0);
add(getid(v,j),getid(u,j+1),0);
add(getid(u,j),getid(v,j),w);
add(getid(v,j),getid(u,j),w);
}
add(getid(u,K),getid(v,K),w);
add(getid(v,K),getid(u,K),w);
}
dij();
int ans=1e9;
for(int i=0;i<=K;i++){
ans=min(ans,dis[getid(T,i)]);
}
cout<<ans<<"\n";
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 349ms
memory: 63860kb
input:
644 1000 425 153 1000 1 2 140463 2 3 969586 2 4 402540 1 5 176573 4 6 860890 4 7 870045 4 8 509023 4...
output:
0
result:
ok "0"
Test #2:
score: 0
Accepted
time: 298ms
memory: 57704kb
input:
476 1000 213 301 1000 1 2 105998 1 3 624420 3 4 305716 4 5 182331 5 6 176444 5 7 31507 5 8 775109 5 ...
output:
0
result:
ok "0"
Test #3:
score: 0
Accepted
time: 493ms
memory: 66436kb
input:
864 1000 597 409 1000 1 2 18950 2 3 574149 1 4 465851 1 5 666564 5 6 131005 3 7 348191 3 8 139339 7 ...
output:
0
result:
ok "0"
Test #4:
score: 0
Accepted
time: 339ms
memory: 57900kb
input:
490 1000 256 162 1000 1 2 525741 2 3 271080 1 4 137739 3 5 156494 4 6 119881 6 7 664514 2 8 586756 5...
output:
0
result:
ok "0"
Test #5:
score: 0
Accepted
time: 379ms
memory: 65504kb
input:
784 1000 286 754 1000 1 2 633328 2 3 521673 2 4 752573 2 5 522253 3 6 410761 6 7 331174 3 8 426641 1...
output:
0
result:
ok "0"
Test #6:
score: 0
Accepted
time: 294ms
memory: 57084kb
input:
422 1000 210 277 1000 1 2 487208 1 3 224998 1 4 262451 3 5 461519 2 6 649350 3 7 780925 2 8 558476 1...
output:
0
result:
ok "0"
Test #7:
score: 0
Accepted
time: 183ms
memory: 54828kb
input:
224 1000 7 68 1000 1 2 851306 1 3 29349 3 4 70350 3 5 533327 1 6 300788 6 7 2114 5 8 575819 5 9 3193...
output:
0
result:
ok "0"
Test #8:
score: 0
Accepted
time: 184ms
memory: 54884kb
input:
227 1000 101 88 1000 1 2 46182 1 3 65425 1 4 906952 3 5 386722 3 6 387381 5 7 441955 4 8 369398 3 9 ...
output:
0
result:
ok "0"
Test #9:
score: 0
Accepted
time: 414ms
memory: 66244kb
input:
847 1000 381 456 1000 1 2 764714 1 3 783422 1 4 506476 4 5 743958 2 6 806574 4 7 766374 5 8 120231 2...
output:
0
result:
ok "0"
Test #10:
score: 0
Accepted
time: 602ms
memory: 67824kb
input:
982 1000 754 713 1000 1 2 797931 1 3 740185 3 4 728627 3 5 376427 1 6 168425 4 7 441955 1 8 516782 1...
output:
0
result:
ok "0"
Subtask #2:
score: 20
Accepted
Test #11:
score: 20
Accepted
time: 0ms
memory: 1268kb
input:
644 1000 425 153 0 1 2 140463 2 3 969586 2 4 402540 1 5 176573 4 6 860890 4 7 870045 4 8 509023 4 9 ...
output:
1593160
result:
ok "1593160"
Test #12:
score: 0
Accepted
time: 0ms
memory: 1260kb
input:
476 1000 213 301 0 1 2 105998 1 3 624420 3 4 305716 4 5 182331 5 6 176444 5 7 31507 5 8 775109 5 9 2...
output:
1881195
result:
ok "1881195"
Test #13:
score: 0
Accepted
time: 0ms
memory: 1268kb
input:
864 1000 597 409 0 1 2 18950 2 3 574149 1 4 465851 1 5 666564 5 6 131005 3 7 348191 3 8 139339 7 9 4...
output:
4813504
result:
ok "4813504"
Test #14:
score: 0
Accepted
time: 0ms
memory: 1264kb
input:
490 1000 256 162 0 1 2 525741 2 3 271080 1 4 137739 3 5 156494 4 6 119881 6 7 664514 2 8 586756 5 9 ...
output:
1548477
result:
ok "1548477"
Test #15:
score: 0
Accepted
time: 1ms
memory: 1268kb
input:
784 1000 286 754 0 1 2 633328 2 3 521673 2 4 752573 2 5 522253 3 6 410761 6 7 331174 3 8 426641 1 9 ...
output:
5172683
result:
ok "5172683"
Test #16:
score: 0
Accepted
time: 0ms
memory: 1260kb
input:
422 1000 210 277 0 1 2 487208 1 3 224998 1 4 262451 3 5 461519 2 6 649350 3 7 780925 2 8 558476 1 9 ...
output:
1650328
result:
ok "1650328"
Test #17:
score: 0
Accepted
time: 1ms
memory: 1260kb
input:
224 1000 7 68 0 1 2 851306 1 3 29349 3 4 70350 3 5 533327 1 6 300788 6 7 2114 5 8 575819 5 9 31935 5...
output:
42537
result:
ok "42537"
Test #18:
score: 0
Accepted
time: 2ms
memory: 1260kb
input:
227 1000 101 88 0 1 2 46182 1 3 65425 1 4 906952 3 5 386722 3 6 387381 5 7 441955 4 8 369398 3 9 155...
output:
671677
result:
ok "671677"
Test #19:
score: 0
Accepted
time: 0ms
memory: 1268kb
input:
847 1000 381 456 0 1 2 764714 1 3 783422 1 4 506476 4 5 743958 2 6 806574 4 7 766374 5 8 120231 2 9 ...
output:
5235960
result:
ok "5235960"
Test #20:
score: 0
Accepted
time: 2ms
memory: 1272kb
input:
982 1000 754 713 0 1 2 797931 1 3 740185 3 4 728627 3 5 376427 1 6 168425 4 7 441955 1 8 516782 1 9 ...
output:
7896193
result:
ok "7896193"
Subtask #3:
score: 70
Accepted
Test #21:
score: 70
Accepted
time: 0ms
memory: 1240kb
input:
1 1000 1 1 0 1 1 325325 1 1 460532 1 1 610307 1 1 382269 1 1 604230 1 1 422654 1 1 48701 1 1 145022 ...
output:
0
result:
ok "0"
Test #22:
score: 0
Accepted
time: 0ms
memory: 1216kb
input:
2 1 2 1 0 1 2 819433
output:
819433
result:
ok "819433"
Test #23:
score: 0
Accepted
time: 0ms
memory: 1304kb
input:
20 1000 19 8 1 13 19 377424 11 13 735834 4 11 787697 9 4 212118 16 9 149405 3 16 495232 18 3 49455 1...
output:
471363
result:
ok "471363"
Test #24:
score: 0
Accepted
time: 0ms
memory: 1344kb
input:
50 1000 18 49 2 42 18 533662 14 42 83260 5 14 515495 17 5 383118 22 17 913368 38 22 784012 20 38 158...
output:
3302937
result:
ok "3302937"
Test #25:
score: 0
Accepted
time: 74ms
memory: 15100kb
input:
998 1000 323 176 233 285 323 960045 987 285 887361 762 987 971829 97 762 419676 141 97 563139 390 14...
output:
305304211
result:
ok "305304211"
Test #26:
score: 0
Accepted
time: 4ms
memory: 3448kb
input:
1000 1000 454 84 37 554 454 97482 570 554 406793 431 570 386698 383 431 745509 607 383 798937 713 60...
output:
466756626
result:
ok "466756626"
Test #27:
score: 0
Accepted
time: 1ms
memory: 1848kb
input:
1000 1000 658 924 10 105 658 1 27 105 1 311 27 1 702 311 1 217 702 1 130 217 1 88 130 1 319 88 1 329...
output:
989
result:
ok "989"
Test #28:
score: 0
Accepted
time: 523ms
memory: 63720kb
input:
1000 1000 620 131 998 364 620 258105 743 364 896437 276 743 401956 691 276 896195 934 691 698840 784...
output:
150
result:
ok "150"
Test #29:
score: 0
Accepted
time: 448ms
memory: 63840kb
input:
1000 1000 758 834 1000 555 758 44469 633 555 148140 197 633 728062 172 197 911720 705 172 700395 288...
output:
0
result:
ok "0"
Test #30:
score: 0
Accepted
time: 0ms
memory: 1252kb
input:
1000 1000 415 153 0 681 415 1000000 538 681 1000000 677 538 1000000 822 677 1000000 506 822 1000000 ...
output:
999000000
result:
ok "999000000"