Submission

Status:

-P--PP-P--

Subtask/Task Score:

40/100

Score: 40

User: tull

Problemset: Fast Delivery

Language: cpp

Time: 0.006 second

Submitted On: 2026-05-06 10:07:54

#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define bp '\n'
#define vp cout<<'\n';
#define all(A) A.begin(),A.end()
using pii=pair<int,int>;
const int MOD=1e9+7;
const int MNLL=-1e18;
const int MXLL=1e18;
const int N=2e5+10;
vector<vector<pii>>a(N);
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int n,m,st,l,r,x;
    cin>>n>>m;
    for(int i=0;i<m;++i){
        cin>>l>>r>>x;
        a[l].emplace_back(r,x);
        a[r].emplace_back(l,x);
    }
    vector<int>d(n+10,MXLL),pre(n+10,-1);
    cin>>st;
    d[st]=0;
    priority_queue<pii,vector<pii>,greater<pii>>pq;
    pq.emplace(0,st);
    while(!pq.empty()){
        auto [dist,src]=pq.top();
        pq.pop();
        if(dist>d[src])continue;
        for(auto&[e,w]:a[src]){
            if(d[e]>d[src]+w){
                d[e]=d[src]+w;
                pre[e]=src;
                pq.emplace(d[e],e);
            }
        }
    }
    for(int i=0;i<n;++i){
        if(st==i)continue;
        cout<<st<<" -> "<<i<<" (";
        if(d[i]==MXLL)cout<<"inf";
        else cout<<d[i];
        cout<<") ";
        int nw=i;
        vector<int>order;
        while(nw!=-1)
        {
            order.emplace_back(nw);
            nw=pre[nw];
        }
        reverse(all(order));
        for(auto&e:order)cout<<e<<' ';
        vp
    }
}