1 条题解
-
0
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL,LL> PII; const int N=1e4+10,K=105; LL n,m,k,d[N];bool v[N]; vector<PII> G[N]; void dijkstra() { memset(d,0x3f,sizeof(d));d[1]=0; memset(v,0,sizeof(v)); priority_queue<PII,vector<PII>,greater<PII>> Q;Q.push({0,1}); while(!Q.empty()) { LL x=Q.top().second,t=Q.top().first; Q.pop(); if(v[x])continue; v[x]=1; for(auto i:G[x]) { LL y=i.first,w=i.second; LL tt=t+1 + ( t<w ? (w-t+k-1)/k*k : 0); if(d[y]>tt) { d[y]=tt; Q.push({tt,y}); } } } } int main() { scanf("%lld%lld%lld",&n,&m,&k); for(LL i=1,x,y,w;i<=m;i++)scanf("%lld%lld%lld",&x,&y,&w),G[x].push_back({y,w}); dijkstra(); printf("%lld\n",(v[n]==1) ? d[n] : -1 ); return 0; }
- 1
信息
- ID
- 640
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 7
- 标签
- 递交数
- 130
- 已通过
- 34
- 上传者