Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : _example
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 14 November 2022 [20:46]
- */
- #include<bits/stdc++.h>
- using namespace std;
- struct A{
- int v,w,state;
- bool operator < (const A&o) const{
- return w>o.w;
- }
- };
- priority_queue<A > heap;
- int dis[5010][110];
- struct B{
- int nextNode,edgeWeight;
- };
- vector<B > g[5010];
- int main(){
- cin.tie(0)->sync_with_stdio(0);
- cin.exceptions(cin.failbit);
- int n,m,k;
- cin >> n >> m >> k;
- for(int i=1;i<=m;i++){
- int u,v,w;
- cin >> u >> v >> w;
- g[u].push_back({v,w});
- g[v].push_back({u,w});
- }
- for(int i=1;i<=n;i++){
- for(int j=0;j<=k;j++){
- dis[i][j] = 1e9;
- }
- }
- dis[1][0] = 0;
- heap.push({1,0,0});
- while(!heap.empty()){
- A now = heap.top();
- heap.pop();
- for(auto x:g[now.v]){
- //special
- if(now.state+1<=k && dis[x.nextNode][now.state+1] > now.w + x.edgeWeight/2){
- dis[x.nextNode][now.state+1] = now.w + x.edgeWeight/2;
- heap.push({x.nextNode,now.w+x.edgeWeight/2,now.state+1});
- }
- //normal
- if(dis[x.nextNode][now.state] > now.w + x.edgeWeight){
- dis[x.nextNode][now.state] = now.w + x.edgeWeight;
- heap.push({x.nextNode,now.w+x.edgeWeight,now.state});
- }
- }
- }
- int mn = 1e9;
- for(int j=0;j<=k;j++)
- mn = min(mn,dis[n][j]);
- cout << dis[n][0] << '\n' << mn << '\n' << dis[n][0]-mn << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment