ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#202540 | #540. 免费 | hegm | 100 | 2433ms | 60672kb | C++11 | 1.4kb | 2024-02-16 08:32:36 | 2024-02-16 12:31:36 |
answer
#include<bits/stdc++.h>
#define make(x,y) make_pair(x,y)
#define N 5000006
using namespace std;
const int inf=2e9;
inline int read()
{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
int n,m,s,u,v,w,cnt,pos,minn,dis[N],head[N],K,t;
bool vis[N];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
struct k
{
int son,val,next;
}k[N];
void add(int a,int b,int c)
{
cnt++;
k[cnt].son=b;
k[cnt].val=c;
k[cnt].next=head[a];
head[a]=cnt;
}
void dij()
{
for(int i=1;i<=n*(K+1);i++)dis[i]=inf;
dis[s]=0;
q.push(make(0,s));
while(!q.empty())
{
pos=q.top().second;
q.pop();
if(vis[pos]==1)continue;
vis[pos]=1;
for(int i=head[pos];i!=0;i=k[i].next)
{
if(dis[k[i].son]>dis[pos]+k[i].val)
{
dis[k[i].son]=dis[pos]+k[i].val;
q.push(make(dis[k[i].son],k[i].son));
}
}
}
}
int main()
{
n=read();m=read();s=read();
t=read();K=read();
for(int i=1;i<=m;i++)
{
u=read();v=read();w=read();
for(int j=0;j<=K;j++)
{
add(u+j*n,v+j*n,w);
add(v+j*n,u+j*n,w);
if(j!=K)
{
add(u+j*n,v+(j+1)*n,0);
add(v+j*n,u+(j+1)*n,0);
}
}
}
dij();
int ans=inf;
for(int i=0;i<=K;i++)ans=min(ans,dis[t+i*n]);
cout<<ans<<"\n";
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 114ms
memory: 53808kb
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: 86ms
memory: 52328kb
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: 139ms
memory: 55772kb
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: 83ms
memory: 52464kb
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: 163ms
memory: 55064kb
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: 143ms
memory: 51856kb
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: 116ms
memory: 50104kb
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: 110ms
memory: 50132kb
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: 213ms
memory: 55628kb
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: 266ms
memory: 56876kb
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: 1252kb
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: 1252kb
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: 1248kb
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: 1252kb
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: 0ms
memory: 1252kb
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: 1ms
memory: 1252kb
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: 0ms
memory: 1248kb
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: 1ms
memory: 1252kb
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: 1248kb
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: 1ms
memory: 1256kb
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: 1ms
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: 1220kb
input:
2 1 2 1 0 1 2 819433
output:
819433
result:
ok "819433"
Test #23:
score: 0
Accepted
time: 1ms
memory: 1288kb
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: 1ms
memory: 1340kb
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: 77ms
memory: 14464kb
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: 7ms
memory: 3324kb
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: 2ms
memory: 1812kb
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: 567ms
memory: 60672kb
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: 341ms
memory: 57544kb
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: 1244kb
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"