#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M)
{
    LL ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

vector < LL > vc[300001], vp[300001],cs[300001];
LL edge[300001][3], dis[300001], res[300001];
priority_queue <pair<int,int> >pq;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    REP(i, m)
    {

        int x, y, v;
        cin >> x >> y >> v;
        vc[x].pb(y);
        vc[y].pb(x);
        cs[x].pb(v);
        cs[y].pb(v);
        vp[x].pb(i);
        vp[y].pb(i);
        edge[i][0] = x;
        edge[i][1] = y;
        edge[i][2] = v;
    }
    int u;
    cin >> u;
   for(int i=0;i<300005;i++)
    dis[i]=1ll<<50;
    dis[u] = 0;
    pq.push(mp(0, u));
    memset(res, -1, sizeof res);
    while(!pq.empty())
    {
        pair < LL, LL > p = pq.top();
        pq.pop();
        int u=p.yy;
        if(dis[u]!=p.xx)
        {
           // cout<<"PORN : "<<dis[u]<<" "<<p.xx;
           // for(;;);
           continue;

        }
        REP(i, vc[u].size())
        {
            int v=vc[u][i];
            if(dis[v] > dis[u] + cs[u][i])
            {
                dis[v] = dis[u] + cs[u][i];
                res[v] = vp[u][i];
                pq.push(mp(dis[v], v));
            }
            else if(dis[v]==dis[u] + cs[u][i])
            {
//                if(edge[ vp[p.yy][i] ][2] <= edge[ res[ vc[p.yy][i] ] ][2])
                {
                    res[v] = vp[u][i];
                }
            }
        }
    }
    LL sum = 0;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        sum += edge[ res[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        cout << res[i]+1 << " ";
    }
    cout << endl;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define ll long long
#define inf (10e12)+5
#define maxi 400005
using namespace std;
struct node
{
    ll city,cost;
    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

vector<ll>G[maxi],dis[maxi];
ll d[maxi];
ll path[maxi];
map<int,map<int,int> > MP,cst;
ll djs(ll src)
{
    for(ll i=0; i<maxi; i++)
        d[i]=1ll<<50,path[i]=-1;

    d[src]=0;
    node a;
    a.city=src,a.cost=0;
    priority_queue<node>Q;
    Q.push(a);
    while(!Q.empty())
    {
        a=Q.top();
        Q.pop();
        ll u=a.city;
        if(a.cost!=d[a.city])
            continue;

        for(ll i=0; i<G[u].size(); i++)
        {

            ll v=G[u][i];
            //  cout<<v<<" ";
            //cout<<d[u]<<" "<<dis[u][i]<<endl;
            if(d[u]+dis[u][i]<d[v])
            {
                //puts("ffffffffff");

                d[v]=d[u]+dis[u][i];
                path[v]=u;
                a.city=v;
                a.cost=d[v];
                Q.push(a);

            }
            else if(d[v]==dis[u][i]+d[u])
            {
                path[v]=u;
//                a.city=v;
//                a.cost=d[v];

            }

        }

    }
//    for(int i=)
//    return -1;
}
//void func(ll v)
//{
//    if(v==-1)
//        return ;
//    ll u=path[v];
//    func(u);
//    cout<<v<<" ";
//}

int main()
{
    ll n,e,u,v,w;
    cin>>n>>e;
    for(ll i=0; i<e; i++)
    {
        cin>>u>>v>>w;
        G[u].push_back(v);
        G[v].push_back(u);
        dis[u].push_back(w);
        dis[v].push_back(w);
        MP[u][v]=i+1;
        MP[v][u]=i+1;
        cst[u][v]=w;
        cst[v][u]=w;

    }
    int src;
    cin>>src;
    djs(src);
    ll ans=0;
    vector<int>V;
    for(int i=1; i<=n; i++)
        if(path[i]!=-1)
        {
            ans+=cst[i][path[i]];

        V.push_back(MP[i][path[i]]);
        }
        cout<<ans<<"\n";
        sort(V.begin(),V.end());
        for(int i=0;i<V.size();i++)
            cout<<V[i]<<" ";

}


#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M)
{
    LL ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

vector < LL > vc[300001], vp[300001];
LL edge[300001][3], dis[300001], res[300001];
priority_queue < pair<LL,LL>, vector<pair<LL,LL> >, greater<pair<LL,LL> > >pq;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    REP(i, m)
    {

        int x, y, v;
        cin >> x >> y >> v;
        vc[x].pb(y);
        vc[y].pb(x);
        vp[x].pb(i);
        vp[y].pb(i);
        edge[i][0] = x;
        edge[i][1] = y;
        edge[i][2] = v;
    }
    int u;
    cin >> u;
   for(int i=0;i<300005;i++)
    dis[i]=1ll<<50;
    dis[u] = 0;
    pq.push(mp(0, u));
    memset(res, -1, sizeof res);
    while(!pq.empty())
    {
        pair < LL, LL > p = pq.top();
        pq.pop();
        int u=p.yy;

        REP(i, vc[u].size())
        {
            int v=vc[u][i];
            if(dis[v] > dis[u] + edge[vp[u][i]][2])
            {
                dis[v] = dis[u] + edge[ vp[u][i] ][2];
                res[v] = vp[u][i];
                pq.push(mp(dis[v], v));
            }
            else if(dis[v]==dis[u] + edge[vp[u][i]][2])
            {
//                if(edge[ vp[p.yy][i] ][2] <= edge[ res[ vc[p.yy][i] ] ][2])
                {
                    res[v] = vp[u][i];
                }
            }
        }
    }
    LL sum = 0;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        sum += edge[ res[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        cout << res[i]+1 << " ";
    }
    cout << endl;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define LL long long
#define inf (10e12)+5
#define maxi 500005
using namespace std;
struct node
{
    LL city,cost;
    node() {}
    node(LL city,LL cost): city(city),cost(cost) {}
    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

vector<LL>G[maxi],dis[maxi],E[maxi];
LL d[maxi],edge[maxi][3];
LL path[maxi];

LL djs(LL src)
{
    for(LL i=0; i<maxi; i++)
        d[i]=inf,path[i]=-1;

    d[src]=0;
   node a;

    priority_queue<node>Q;
    Q.push(node(src,0));
    while(!Q.empty())
    {
        a=Q.top();
        Q.pop();
        LL u=a.city;
        if(a.cost!=d[u])continue;

        for(LL i=0; i<G[u].size(); i++)
        {

            LL v=G[u][i];

            //  cout<<v<<" ";
            //cout<<d[u]<<" "<<dis[u][i]<<endl;
            if(d[u]+dis[u][i]<d[v])
            {
                //puts("ffffffffff");

                d[v]=d[u]+dis[u][i];
                path[v]=E[u][i];
                Q.push(node(v,d[v]));

            }
            else if(d[v]==dis[u][i]+d[u])
            {
                path[v]=E[u][i];
//                a.city=v;
//                a.cost=d[v];

            }

        }

    }
//    for(int i=)
//    return -1;
}
//void func(LL v)
//{
//    if(v==-1)
//        return ;
//    LL u=path[v];
//    func(u);
//    cout<<v<<" ";
//}

int main()
{
    LL n,e,u,v,w;
    cin>>n>>e;
    for(LL i=0; i<e; i++)
    {
        cin>>u>>v>>w;
        G[u].push_back(v);
        G[v].push_back(u);
        dis[u].push_back(w);
        dis[v].push_back(w);
        E[u].push_back(i);
        E[v].push_back(i);
        edge[i][0]=u,edge[i][1]=v,edge[i][2]=w;

    }
    int src;
    cin>>src;
    djs(src);
//    LL ans=0;
//    vector<int>V;

      LL sum = 0;
    for(int i=1;i<=n;i++)
    {
        if(path[i] == -1) continue;
        sum += edge[ path[i] ][2];
    }
    cout << sum << endl;
    for(int i=1;i<=n;i++)
    {
        if(path[i] == -1) continue;
        cout << path[i]+1 << " ";
    }
    cout << endl;

}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define ll long long
#define inf (10e12)+5
#define maxi 100005
using namespace std;
struct node
{
    ll city,cost;
    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

vector<ll>G[maxi],dis[maxi];
ll d[maxi];
ll path[maxi];
map<int,map<int,int> > MP,cst;
ll djs(ll src)
{
    for(ll i=0; i<maxi; i++)
        d[i]=inf,path[i]=-1;

    d[src]=0;
    node a;
    a.city=src,a.cost=0;
    priority_queue<node>Q;
    Q.push(a);
    while(!Q.empty())
    {
        a=Q.top();
        Q.pop();
        ll u=a.city;
        if(a.cost!=d[u])continue;

        for(ll i=0; i<G[u].size(); i++)
        {

            ll v=G[u][i];

            //  cout<<v<<" ";
            //cout<<d[u]<<" "<<dis[u][i]<<endl;
            if(d[u]+dis[u][i]<d[v])
            {
                //puts("ffffffffff");

                d[v]=d[u]+dis[u][i];
                path[v]=u;
                a.city=v;
                a.cost=d[v];
                Q.push(a);

            }
            else if(d[v]==dis[u][i]+d[u])
            {
                path[v]=u;
//                a.city=v;
//                a.cost=d[v];

            }

        }

    }
//    for(int i=)
//    return -1;
}
//void func(ll v)
//{
//    if(v==-1)
//        return ;
//    ll u=path[v];
//    func(u);
//    cout<<v<<" ";
//}

int main()
{
    ll n,e,u,v,w;
    cin>>n>>e;
    for(ll i=0; i<e; i++)
    {
        cin>>u>>v>>w;
        G[u].push_back(v);
        G[v].push_back(u);
        dis[u].push_back(w);
        dis[v].push_back(w);
        MP[u][v]=i+1;
        MP[v][u]=i+1;
        cst[u][v]=w;
        cst[v][u]=w;

    }
    int src;
    cin>>src;
    djs(src);
    int ans=0;
    vector<int>V;
    for(int i=1; i<=n; i++)
        if(path[i]!=-1)
        {
            ans+=cst[i][path[i]];

        V.push_back(MP[i][path[i]]);
        }
        cout<<ans<<"\n";
        sort(V.begin(),V.end());
        for(int i=0;i<V.size();i++)
            cout<<V[i]<<" ";
//   ll ans=djs(1,n);
//   if(ans==-1)
//    cout<<ans<<endl;
//    else
//    {
//        func(n);
//        puts("");
//    }

}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define ll long long
#define inf (10e12)+5
#define maxi 100005
using namespace std;
struct node
{
    ll city,cost;
    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

vector<ll>G[maxi],dis[maxi],E[maxi];
ll d[maxi];
ll path[maxi];
int edge[maxi][5];
ll djs(ll src)
{
    for(ll i=0; i<maxi; i++)
        d[i]=inf,path[i]=-1;

    d[src]=0;
    node a;

    a.city=src,a.cost=0;
    priority_queue<node>Q;
    Q.push(a);

    while(!Q.empty())
    {
        a=Q.top();
        Q.pop();
        ll u=a.city;

        for(ll i=0; i<G[u].size(); i++)
        {

            ll v=G[u][i];
            //  cout<<v<<" ";
            //cout<<d[u]<<" "<<dis[u][i]<<endl;
            if(d[u]+dis[u][i]<d[v])
            {
                //puts("ffffffffff");

                d[v]=d[u]+dis[u][i];
                path[v]=E[u][i];
                a.city=v;
                a.cost=d[v];
                Q.push(a);

            }
            else if(d[v]==dis[u][i]+d[u])
            {
                path[v]=E[u][i];
//                a.city=v;
//                a.cost=d[v];

            }

        }

    }

}
//void func(ll v)
//{
//    if(v==-1)
//        return ;
//    ll u=path[v];
//    func(u);
//    cout<<v<<" ";
//}
#define PB push_back
int main()
{
    ll n,e,u,v,w;
    cin>>n>>e;
    for(ll i=0; i<e; i++)
    {
        cin>>u>>v>>w;
        G[u].push_back(v);
        G[v].push_back(u);
        E[u].PB(i+1);
        E[v].PB(i+1);
        edge[i+1][0]=u,edge[i+1][1]=v,edge[i+1][2]=w;
        dis[u].push_back(w);
        dis[v].push_back(w);

    }
    int src;
    cin>>src;
    djs(src);
    int ans=0;
    for(int i=1; i<=n; i++)
        if(path[i]!=-1)
        {
            ans+=edge[path[i]][2];
        }
cout<<ans<<"\n";
    for(int i=1; i<=n; i++)
        if(path[i]!=-1)
        {
            cout<<path[i]<<" ";
//            ans+=edge[path[i]][2];
        }
//    vector<int>V;
//    for(int i=1; i<=n; i++)
//        if(path[i]!=-1)
//        {
//            ans+=cst[i][path[i]];
//
//        V.push_back(MP[i][path[i]]);
//        }
//        cout<<ans<<"\n";
//        sort(V.begin(),V.end());
//        for(int i=0;i<V.size();i++)
//            cout<<V[i]<<" ";
//   ll ans=djs(1,n);
//   if(ans==-1)
//    cout<<ans<<endl;
//    else
//    {
//        func(n);
//        puts("");
//    }

}


#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M)
{
    LL ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

vector < LL > G[300001], E[300001],dis[300001];
LL edge[300001][3], d[300001], path[300001];
struct node
{
    LL city,cost;
    node() {}
    node(LL city,LL cost): city(city),cost(cost) {}
    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

priority_queue <node>Q;
int main()
{

     LL n,e,u,v,w;
    cin>>n>>e;
    for(LL i=0; i<e; i++)
    {
        cin>>u>>v>>w;
        G[u].push_back(v);
        G[v].push_back(u);
        dis[u].push_back(w);
        dis[v].push_back(w);
        E[u].push_back(i);
        E[v].push_back(i);
        edge[i][0]=u,edge[i][1]=v,edge[i][2]=w;

    }

    int src;
//    cin >> src;
//    for(int i=0; i<300005; i++)
//        d[i]=1ll<<50;
//
//    d[src] = 0;
//    Q.push(node(src,0));
//    memset(path, -1, sizeof path);
  cin>>src;
    for(LL i=0; i<300005; i++)
        d[i]=inf,path[i]=-1;

    d[src]=0;
    node a;

    priority_queue<node>Q;
    Q.push(node(src,0));

  while(!Q.empty())
    {
        node a;
        a=Q.top();
        Q.pop();
        LL u=a.city;
        if(a.cost!=d[u])continue;

        for(LL i=0; i<G[u].size(); i++)
        {

            LL v=G[u][i];

            //  cout<<v<<" ";
            //cout<<d[u]<<" "<<dis[u][i]<<endl;
            if(d[u]+dis[u][i]<d[v])
            {
                //puts("ffffffffff");

                d[v]=d[u]+dis[u][i];
                path[v]=E[u][i];
                Q.push(node(v,d[v]));

            }
            else if(d[v]==dis[u][i]+d[u])
            {
                path[v]=E[u][i];

            }

        }

    }

    LL sum = 0;
    FOR(i, 1, n+1)
    {
        if(path[i] == -1) continue;
        sum += edge[ path[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1)
    {
        if(path[i] == -1) continue;
        cout << path[i]+1 << " ";
    }
    cout << endl;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define ll long long
#define inf (10e12)+5
#define maxi 500005
using namespace std;
struct node
{
    ll city,cost;
    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

vector<ll>G[maxi],dis[maxi];
ll d[maxi];
ll path[maxi];
map<int,map<int,int> > MP,cst;
ll djs(ll src)
{
    for(ll i=0; i<maxi; i++)
        d[i]=inf,path[i]=-1;

    d[src]=0;
    node a;
    a.city=src,a.cost=0;
    priority_queue<node>Q;
    Q.push(a);
    while(!Q.empty())
    {
        a=Q.top();
        Q.pop();
        ll u=a.city;
        if(a.cost!=d[u])continue;

        for(ll i=0; i<G[u].size(); i++)
        {

            ll v=G[u][i];

            //  cout<<v<<" ";
            //cout<<d[u]<<" "<<dis[u][i]<<endl;
            if(d[u]+dis[u][i]<d[v])
            {
                //puts("ffffffffff");

                d[v]=d[u]+dis[u][i];
                path[v]=u;
                a.city=v;
                a.cost=d[v];
                Q.push(a);

            }
            else if(d[v]==dis[u][i]+d[u])
            {
                path[v]=u;
//                a.city=v;
//                a.cost=d[v];

            }

        }

    }
//    for(int i=)
//    return -1;
}
//void func(ll v)
//{
//    if(v==-1)
//        return ;
//    ll u=path[v];
//    func(u);
//    cout<<v<<" ";
//}

int main()
{
    ll n,e,u,v,w;
    cin>>n>>e;
    for(ll i=0; i<e; i++)
    {
        cin>>u>>v>>w;
        G[u].push_back(v);
        G[v].push_back(u);
        dis[u].push_back(w);
        dis[v].push_back(w);
        MP[u][v]=i+1;
        MP[v][u]=i+1;
        cst[u][v]=w;
        cst[v][u]=w;

    }
    int src;
    cin>>src;
    djs(src);
    ll ans=0;
    vector<int>V;
    for(int i=1; i<=n; i++)
        if(path[i]!=-1)
        {
            ans+=cst[i][path[i]];

        V.push_back(MP[i][path[i]]);
        }
        cout<<ans<<"\n";
        sort(V.begin(),V.end());
        for(int i=0;i<V.size();i++)
            cout<<V[i]<<" ";
//   ll ans=djs(1,n);
//   if(ans==-1)
//    cout<<ans<<endl;
//    else
//    {
//        func(n);
//        puts("");
//    }

}


#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M)
{
    LL ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

vector < LL > vc[300001], vp[300001],cs[300001];
LL edge[300001][3], dis[300001], res[300001];
struct node
{
    LL city,cost;
    node() {}
    node(LL city,LL cost): city(city),cost(cost) {}
    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

priority_queue <node>pq;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    REP(i, m)
    {

        int x, y, v;
        cin >> x >> y >> v;
        vc[x].pb(y);
        vc[y].pb(x);
        cs[x].pb(v);
        cs[y].pb(v);
        vp[x].pb(i);
        vp[y].pb(i);
        edge[i][0] = x;
        edge[i][1] = y;
        edge[i][2] = v;
    }
    int u;
    cin >> u;
    for(int i=0; i<300005; i++)
        dis[i]=1ll<<50;

    dis[u] = 0;
    pq.push(node(u,0));
    memset(res, -1, sizeof res);
    while(!pq.empty())
    {
        node p = pq.top();
        pq.pop();
        int u=p.city;
        if(dis[u]!=p.cost)
        {
            // cout<<"PORN : "<<dis[u]<<" "<<p.xx;
            // for(;;);
            continue;

        }
        REP(i, vc[u].size())
        {
            int v=vc[u][i];
            if(dis[v] > dis[u] + cs[u][i])
            {
                dis[v] = dis[u] + cs[u][i];
                res[v] = vp[u][i];
                pq.push(node(v,dis[v]));
            }
            else if(dis[v]==dis[u] + cs[u][i])
            {
//                if(edge[ vp[p.yy][i] ][2] <= edge[ res[ vc[p.yy][i] ] ][2])
                {
                    res[v] = vp[u][i];
                }
            }
        }
    }
    LL sum = 0;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        sum += edge[ res[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        cout << res[i]+1 << " ";
    }
    cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M)
{
    LL ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

vector < LL > vc[300001], vp[300001];
LL edge[300001][3], dis[300001], res[300001];
priority_queue < pair<LL,LL>, vector<pair<LL,LL> >, greater<pair<LL,LL> > >pq;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    REP(i, m)
    {

        int x, y, v;
        cin >> x >> y >> v;
        vc[x].pb(y);
        vc[y].pb(x);
        vp[x].pb(i);
        vp[y].pb(i);
        edge[i][0] = x;
        edge[i][1] = y;
        edge[i][2] = v;
    }
    int u;
    cin >> u;
   for(int i=0;i<300005;i++)
    dis[i]=1ll<<50;
    dis[u] = 0;
    pq.push(mp(0, u));
    memset(res, -1, sizeof res);
    while(!pq.empty())
    {
        pair < LL, LL > p = pq.top();
        pq.pop();
        int u=p.yy;
        if(dis[u]!=p.xx)
        {
           // cout<<"PORN : "<<dis[u]<<" "<<p.xx;
           // for(;;);
           continue;

        }
        REP(i, vc[u].size())
        {
            int v=vc[u][i];
            if(dis[v] > dis[u] + edge[vp[u][i]][2])
            {
                dis[v] = dis[u] + edge[ vp[u][i] ][2];
                res[v] = vp[u][i];
                pq.push(mp(dis[v], v));
            }
            else if(dis[v]==dis[u] + edge[vp[u][i]][2])
            {
//                if(edge[ vp[p.yy][i] ][2] <= edge[ res[ vc[p.yy][i] ] ][2])
                {
                    res[v] = vp[u][i];
                }
            }
        }
    }
    LL sum = 0;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        sum += edge[ res[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        cout << res[i]+1 << " ";
    }
    cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M)
{
    LL ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

vector < LL > G[300001], E[300001],dis[300001];
LL edge[300001][3], d[300001], path[300001];
struct node
{
    LL city,cost;
    node() {}
    node(LL city,LL cost): city(city),cost(cost) {}
    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

priority_queue <node>Q;
int main()
{

    int n, m;
    cin >> n >> m;
    REP(i, m)
    {

        int x, y, v;
        cin >> x >> y >> v;
        G[x].pb(y);
        G[y].pb(x);
        dis[x].pb(v);
        dis[y].pb(v);
        E[x].pb(i);
        E[y].pb(i);

        edge[i][0] = x;
        edge[i][1] = y;
        edge[i][2] = v;
    }
    int u;
    cin >> u;
    for(int i=0; i<300005; i++)
        d[i]=1ll<<50;

    d[u] = 0;
    Q.push(node(u,0));
    memset(path, -1, sizeof path);
    while(!Q.empty())
    {
        node p = Q.top();
        Q.pop();
        int u=p.city;
        if(d[u]!=p.cost)
        {
            // cout<<"PORN : "<<d[u]<<" "<<p.xx;
            // for(;;);
            continue;

        }
        REP(i, G[u].size())
        {
            int v=G[u][i];
            if(d[v] > d[u] + dis[u][i])
            {
                d[v] = d[u] + dis[u][i];
                path[v] = E[u][i];
                Q.push(node(v,d[v]));
            }
            else if(d[v]==d[u] + dis[u][i])
            {
//                if(edge[ E[p.yy][i] ][2] <= edge[ path[ G[p.yy][i] ] ][2])
                    path[v] = E[u][i];
            }
        }
    }
    LL sum = 0;
    FOR(i, 1, n+1)
    {
        if(path[i] == -1) continue;
        sum += edge[ path[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1)
    {
        if(path[i] == -1) continue;
        cout << path[i]+1 << " ";
    }
    cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M)
{
    LL ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

vector < LL > vc[300001], vp[300001],cs[300001];
LL edge[300001][3], dis[300001], res[300001];
priority_queue < pair<LL,LL> >pq;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    REP(i, m)
    {

        int x, y, v;
        cin >> x >> y >> v;
        vc[x].pb(y);
        vc[y].pb(x);
        cs[x].pb(v);
        cs[y].pb(v);
        vp[x].pb(i);
        vp[y].pb(i);
        edge[i][0] = x;
        edge[i][1] = y;
        edge[i][2] = v;
    }
    int u;
    cin >> u;
   for(int i=0;i<300005;i++)
    dis[i]=1ll<<50;
    dis[u] = 0;
    pq.push(mp(0, u));
    memset(res, -1, sizeof res);
    while(!pq.empty())
    {
        pair < LL, LL > p = pq.top();
        pq.pop();
        int u=p.yy;
        if(dis[u]!=p.xx)
        {
           // cout<<"PORN : "<<dis[u]<<" "<<p.xx;
           // for(;;);
           continue;

        }
        REP(i, vc[u].size())
        {
            int v=vc[u][i];
            if(dis[v] > dis[u] + cs[u][i])
            {
                dis[v] = dis[u] + cs[u][i];
                res[v] = vp[u][i];
                pq.push(mp(dis[v], v));
            }
            else if(dis[v]==dis[u] + cs[u][i])
            {
//                if(edge[ vp[p.yy][i] ][2] <= edge[ res[ vc[p.yy][i] ] ][2])
                {
                    res[v] = vp[u][i];
                }
            }
        }
    }
    LL sum = 0;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        sum += edge[ res[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        cout << res[i]+1 << " ";
    }
    cout << endl;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define LL long long
#define inf (10e12)+5
#define maxi 500005
using namespace std;
struct node
{
    LL city,cost;
    node() {}
    node(LL city,LL cost): city(city),cost(cost) {}
    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

vector<LL>G[maxi],dis[maxi],E[maxi];
LL d[maxi],edge[maxi][3];
LL path[maxi];

LL djs(LL src)
{

//    for(int i=)
//    return -1;
}
//void func(LL v)
//{
//    if(v==-1)
//        return ;
//    LL u=path[v];
//    func(u);
//    cout<<v<<" ";
//}

int main()
{
    LL n,e,u,v,w;
    cin>>n>>e;
    for(LL i=0; i<e; i++)
    {
        cin>>u>>v>>w;
        G[u].push_back(v);
        G[v].push_back(u);
        dis[u].push_back(w);
        dis[v].push_back(w);
        E[u].push_back(i);
        E[v].push_back(i);
        edge[i][0]=u,edge[i][1]=v,edge[i][2]=w;

    }
    int src;
    cin>>src;
    for(LL i=0; i<maxi; i++)
        d[i]=inf,path[i]=-1;

    d[src]=0;
    node a;

    priority_queue<node>Q;
    Q.push(node(src,0));
    while(!Q.empty())
    {
        a=Q.top();
        Q.pop();
        LL u=a.city;
        if(a.cost!=d[u])continue;

        for(LL i=0; i<G[u].size(); i++)
        {

            LL v=G[u][i];

            //  cout<<v<<" ";
            //cout<<d[u]<<" "<<dis[u][i]<<endl;
            if(d[u]+dis[u][i]<d[v])
            {
                //puts("ffffffffff");

                d[v]=d[u]+dis[u][i];
                path[v]=E[u][i];
                Q.push(node(v,d[v]));

            }
            else if(d[v]==dis[u][i]+d[u])
            {
                path[v]=E[u][i];

            }

        }

    }
    LL sum = 0;
    for(int i=1; i<=n; i++)
    {
        if(path[i] == -1) continue;
        sum += edge[ path[i] ][2];
    }
    cout << sum << endl;
    for(int i=1; i<=n; i++)
    {
        if(path[i] == -1) continue;
        cout << path[i]+1 << " ";
    }
    cout << endl;

}


#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

vector < LL > vc[300001], vp[300001];
LL edge[300001][3], dis[300001], res[300001];
priority_queue < pair<LL,LL>, vector<pair<LL,LL> >, greater<pair<LL,LL> > >pq;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m; cin >> n >> m;
    REP(i, m){
        int x, y, v; cin >> x >> y >> v;
        vc[x].pb(y);
        vc[y].pb(x);
        vp[x].pb(i);
        vp[y].pb(i);
        edge[i][0] = x; edge[i][1] = y; edge[i][2] = v;
    }
    int u; cin >> u;
    setinf(dis);
    dis[u] = 0;
    pq.push(mp(0, u));
    memset(res, -1, sizeof res);
    while(!pq.empty()){
        pair < LL, LL > p = pq.top();
        pq.pop();
        REP(i, vc[p.yy].size()){
            if(dis[ vc[p.yy][i] ] > p.xx + edge[ vp[p.yy][i] ][2]){
                dis[ vc[p.yy][i] ] = p.xx + edge[ vp[p.yy][i] ][2];
                res[ vc[p.yy][i] ] = vp[p.yy][i];
                pq.push(mp(dis[ vc[p.yy][i] ], vc[p.yy][i]));
            } else if(dis[ vc[p.yy][i] ] == p.xx + edge[ vp[p.yy][i] ][2]){
//                if(edge[ vp[p.yy][i] ][2] <= edge[ res[ vc[p.yy][i] ] ][2])
                    {
                    res[ vc[p.yy][i] ] = vp[p.yy][i];
                }
            }
        }
    }
    LL sum = 0;
    FOR(i, 1, n+1){
        if(res[i] == -1) continue;
        sum += edge[ res[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1){
        if(res[i] == -1) continue;
        cout << res[i]+1 << " ";
    }
    cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M)
{
    LL ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

vector < LL > G[300001], E[300001],dis[300001];
LL edge[300001][3], d[300001], path[300001];
struct node
{
    LL city,cost;
    node() {}
    node(LL city,LL cost): city(city),cost(cost) {}
    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

priority_queue <node>Q;
int main()
{

     LL n,e,u,v,w;
    cin>>n>>e;
    for(LL i=0; i<e; i++)
    {
        cin>>u>>v>>w;
        G[u].push_back(v);
        G[v].push_back(u);
        dis[u].push_back(w);
        dis[v].push_back(w);
        E[u].push_back(i);
        E[v].push_back(i);
        edge[i][0]=u,edge[i][1]=v,edge[i][2]=w;

    }
    int src;
    cin >> src;
    for(int i=0; i<300005; i++)
        d[i]=1ll<<50;

    d[src] = 0;
    Q.push(node(src,0));
    memset(path, -1, sizeof path);
    while(!Q.empty())
    {
        node p = Q.top();
        Q.pop();
        int u=p.city;
        if(d[u]!=p.cost)
        {
            // cout<<"PORN : "<<d[u]<<" "<<p.xx;
            // for(;;);
            continue;

        }
        REP(i, G[u].size())
        {
            int v=G[u][i];
            if(d[v] > d[u] + dis[u][i])
            {
                d[v] = d[u] + dis[u][i];
                path[v] = E[u][i];
                Q.push(node(v,d[v]));
            }
            else if(d[v]==d[u] + dis[u][i])
            {
//                if(edge[ E[p.yy][i] ][2] <= edge[ path[ G[p.yy][i] ] ][2])
                    path[v] = E[u][i];
            }
        }
    }
    LL sum = 0;
    FOR(i, 1, n+1)
    {
        if(path[i] == -1) continue;
        sum += edge[ path[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1)
    {
        if(path[i] == -1) continue;
        cout << path[i]+1 << " ";
    }
    cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M)
{
    LL ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

vector < LL > vc[300001], vp[300001];
LL edge[300001][3], dis[300001], res[300001];
priority_queue < pair<LL,LL>, vector<pair<LL,LL> >, greater<pair<LL,LL> > >pq;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    REP(i, m)
    {

        int x, y, v;
        cin >> x >> y >> v;
        vc[x].pb(y);
        vc[y].pb(x);
        vp[x].pb(i);
        vp[y].pb(i);
        edge[i][0] = x;
        edge[i][1] = y;
        edge[i][2] = v;
    }
    int u;
    cin >> u;
   for(int i=0;i<300005;i++)
    dis[i]=1ll<<50;
    dis[u] = 0;
    pq.push(mp(0, u));
    memset(res, -1, sizeof res);
    while(!pq.empty())
    {
        pair < LL, LL > p = pq.top();
        pq.pop();
        int u=p.yy;
        if(dis[u]!=p.xx)
        {
            cout<<"PORN : "<<dis[u]<<" "<<p.xx;
           // for(;;);

        }
        REP(i, vc[u].size())
        {
            int v=vc[u][i];
            if(dis[v] > dis[u] + edge[vp[u][i]][2])
            {
                dis[v] = dis[u] + edge[ vp[u][i] ][2];
                res[v] = vp[u][i];
                pq.push(mp(dis[v], v));
            }
            else if(dis[v]==dis[u] + edge[vp[u][i]][2])
            {
//                if(edge[ vp[p.yy][i] ][2] <= edge[ res[ vc[p.yy][i] ] ][2])
                {
                    res[v] = vp[u][i];
                }
            }
        }
    }
    LL sum = 0;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        sum += edge[ res[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        cout << res[i]+1 << " ";
    }
    cout << endl;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define ll long long
#define inf (10e12)+5
#define maxi 400005
using namespace std;
struct node
{
    ll city,cost;
    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

vector<ll>G[maxi],dis[maxi];
ll d[maxi];
ll path[maxi];
map<int,map<int,int> > MP,cst;
ll djs(ll src)
{
    for(ll i=0; i<maxi; i++)
        d[i]=1ll<<50,path[i]=-1;

    d[src]=0;
    node a;
    a.city=src,a.cost=0;
    priority_queue<node>Q;
    Q.push(a);
    while(!Q.empty())
    {
        a=Q.top();
        Q.pop();
        ll u=a.city;

        for(ll i=0; i<G[u].size(); i++)
        {

            ll v=G[u][i];
            //  cout<<v<<" ";
            //cout<<d[u]<<" "<<dis[u][i]<<endl;
            if(d[u]+dis[u][i]<d[v])
            {
                //puts("ffffffffff");

                d[v]=d[u]+dis[u][i];
                path[v]=u;
                a.city=v;
                a.cost=d[v];
                Q.push(a);

            }
            else if(d[v]==dis[u][i]+d[u])
            {
                path[v]=u;
//                a.city=v;
//                a.cost=d[v];

            }

        }

    }
//    for(int i=)
//    return -1;
}
//void func(ll v)
//{
//    if(v==-1)
//        return ;
//    ll u=path[v];
//    func(u);
//    cout<<v<<" ";
//}

int main()
{
    ll n,e,u,v,w;
    cin>>n>>e;
    for(ll i=0; i<e; i++)
    {
        cin>>u>>v>>w;
        G[u].push_back(v);
        G[v].push_back(u);
        dis[u].push_back(w);
        dis[v].push_back(w);
        MP[u][v]=i+1;
        MP[v][u]=i+1;
        cst[u][v]=w;
        cst[v][u]=w;

    }
    int src;
    cin>>src;
    djs(src);
    ll ans=0;
    vector<int>V;
    for(int i=1; i<=n; i++)
        if(path[i]!=-1)
        {
            ans+=cst[i][path[i]];

        V.push_back(MP[i][path[i]]);
        }
        cout<<ans<<"\n";
        sort(V.begin(),V.end());
        for(int i=0;i<V.size();i++)
            cout<<V[i]<<" ";

}


#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M)
{
    LL ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

vector < LL > vc[300001], vp[300001];
LL edge[300001][3], dis[300001], res[300001];
priority_queue < pair<LL,LL>, vector<pair<LL,LL> >, greater<pair<LL,LL> > >pq;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    REP(i, m)
    {
        int x, y, v;
        cin >> x >> y >> v;
        vc[x].pb(y);
        vc[y].pb(x);
        vp[x].pb(i);
        vp[y].pb(i);
        edge[i][0] = x;
        edge[i][1] = y;
        edge[i][2] = v;
    }
    int u;
    cin >> u;
    setinf(dis);
    dis[u] = 0;
    pq.push(mp(0, u));
    memset(res, -1, sizeof res);
    while(!pq.empty())
    {
        pair < LL, LL > p = pq.top();
        pq.pop();
        int u=p.yy;

        REP(i, vc[u].size())
        {
            int v=vc[u][i];
            if(dis[v] > p.xx + edge[vp[u][i]][2])
            {
                dis[v] = p.xx + edge[ vp[u][i] ][2];
                res[v] = vp[u][i];
                pq.push(mp(dis[v], v));
            }
            else if(dis[v]==p.xx + edge[vp[u][i]][2])
            {
//                if(edge[ vp[p.yy][i] ][2] <= edge[ res[ vc[p.yy][i] ] ][2])
                {
                    res[v] = vp[u][i];
                }
            }
        }
    }
    LL sum = 0;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        sum += edge[ res[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        cout << res[i]+1 << " ";
    }
    cout << endl;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define LL long long
#define inf (10e12)+5
#define maxi 500005
using namespace std;
struct node
{
    LL city,cost;
    node() {}
    node(LL city,LL cost): city(city),cost(cost) {}
    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

vector<LL>G[maxi],dis[maxi],E[maxi];
LL d[maxi],edge[maxi][3];
LL path[maxi];

int main()
{
    LL n,e,u,v,w;
    cin>>n>>e;
    for(LL i=0; i<e; i++)
    {
        cin>>u>>v>>w;
        G[u].push_back(v);
        G[v].push_back(u);
        dis[u].push_back(w);
        dis[v].push_back(w);
        E[u].push_back(i);
        E[v].push_back(i);
        edge[i][0]=u,edge[i][1]=v,edge[i][2]=w;

    }
    int src;
    cin>>src;
    for(LL i=0; i<maxi; i++)
        d[i]=1ll<<50,path[i]=-1;

    d[src]=0;
    node a;

    priority_queue<node>Q;
    Q.push(node(src,0));
    while(!Q.empty())
    {
        a=Q.top();
        Q.pop();
        LL u=a.city;
        if(a.cost!=d[u])continue;

        for(LL i=0; i<G[u].size(); i++)
        {

            LL v=G[u][i];

            //  cout<<v<<" ";
            //cout<<d[u]<<" "<<dis[u][i]<<endl;
            if(d[u]+dis[u][i]<d[v])
            {
                //puts("ffffffffff");

                d[v]=d[u]+dis[u][i];
                path[v]=E[u][i];
                Q.push(node(v,d[v]));

            }
            else if(d[v]==dis[u][i]+d[u])
            {
                path[v]=E[u][i];

            }

        }

    }
    LL sum = 0;
    for(int i=1; i<=n; i++)
    {
        if(path[i] == -1) continue;
        sum += edge[ path[i] ][2];
    }
    cout << sum << endl;
    for(int i=1; i<=n; i++)
    {
        if(path[i] == -1) continue;
        cout << path[i]+1 << " ";
    }
    cout << endl;

}


#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M)
{
    LL ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

vector < LL > vc[300001], vp[300001];
LL edge[300001][3], dis[300001], res[300001];
priority_queue < pair<LL,LL>, vector<pair<LL,LL> >, greater<pair<LL,LL> > >pq;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    REP(i, m)
    {

        int x, y, v;
        cin >> x >> y >> v;
        vc[x].pb(y);
        vc[y].pb(x);
        vp[x].pb(i);
        vp[y].pb(i);
        edge[i][0] = x;
        edge[i][1] = y;
        edge[i][2] = v;
    }
    int u;
    cin >> u;
   for(int i=0;i<300005;i++)
    dis[i]=1ll<<50;
    dis[u] = 0;
    pq.push(mp(0, u));
    memset(res, -1, sizeof res);
    while(!pq.empty())
    {
        pair < LL, LL > p = pq.top();
        pq.pop();
        int u=p.yy;
        if(dis[u]!=p.xx)
        {
            cout<<"PORN : "<<dis[u]<<" "<<p.xx;
            for(;;);

        }
        REP(i, vc[u].size())
        {
            int v=vc[u][i];
            if(dis[v] > dis[u] + edge[vp[u][i]][2])
            {
                dis[v] = dis[u] + edge[ vp[u][i] ][2];
                res[v] = vp[u][i];
                pq.push(mp(dis[v], v));
            }
            else if(dis[v]==dis[u] + edge[vp[u][i]][2])
            {
//                if(edge[ vp[p.yy][i] ][2] <= edge[ res[ vc[p.yy][i] ] ][2])
                {
                    res[v] = vp[u][i];
                }
            }
        }
    }
    LL sum = 0;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        sum += edge[ res[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        cout << res[i]+1 << " ";
    }
    cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M)
{
    LL ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

vector < LL > vc[300001], vp[300001];
LL edge[300001][3], dis[300001], res[300001];
priority_queue < pair<LL,LL>, vector<pair<LL,LL> >, greater<pair<LL,LL> > >pq;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    REP(i, m)
    {
        int x, y, v;
        cin >> x >> y >> v;
        vc[x].pb(y);
        vc[y].pb(x);
        vp[x].pb(i);
        vp[y].pb(i);
        edge[i][0] = x;
        edge[i][1] = y;
        edge[i][2] = v;
    }
    int u;
    cin >> u;
    setinf(dis);
    dis[u] = 0;
    pq.push(mp(0, u));
    memset(res, -1, sizeof res);
    while(!pq.empty())
    {
        pair < LL, LL > p = pq.top();
        pq.pop();
        int u=p.yy;

        REP(i, vc[u].size())
        {
            int v=vc[u][i];
            if(dis[v] > dis[u] + edge[vp[u][i]][2])
            {
                dis[v] = dis[u] + edge[ vp[u][i] ][2];
                res[v] = vp[u][i];
                pq.push(mp(dis[v], v));
            }
            else if(dis[v]==dis[u] + edge[vp[u][i]][2])
            {
//                if(edge[ vp[p.yy][i] ][2] <= edge[ res[ vc[p.yy][i] ] ][2])
                {
                    res[v] = vp[u][i];
                }
            }
        }
    }
    LL sum = 0;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        sum += edge[ res[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        cout << res[i]+1 << " ";
    }
    cout << endl;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define ll long long
#define inf (10e12)+5
#define maxi 400005
using namespace std;
struct node
{
    ll city,cost;

    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

vector<ll>G[maxi],dis[maxi],E[maxi];
ll d[maxi];
ll path[maxi];
int edge[maxi][5];
ll djs(ll src)
{
    for(ll i=0; i<maxi; i++)
        d[i]=inf,path[i]=-1;

    d[src]=0;
    node a;

    a.city=src,a.cost=0;
    priority_queue<node>Q;
    Q.push(a);

    while(!Q.empty())
    {
        a=Q.top();
        Q.pop();

        for(ll i=0; i<G[a.city].size(); i++)
        {

            //  cout<<v<<" ";
            //cout<<d[u]<<" "<<dis[u][i]<<endl;
            if(a.cost+edge[E[a.city][i]][2]<d[G[a.city][i]])
            {
                //puts("ffffffffff");

                d[G[a.city][i]]=a.cost+edge[E[a.city][i]][2];
                path[G[a.city][i]]=E[a.city][i];
                node b;
                b.city=G[a.city][i];
                b.cost=d[G[a.city][i]];
                Q.push(b);

            }
            else if(a.cost+edge[E[a.city][i]][2]==d[G[a.city][i]])

            {
                path[G[a.city][i]]=E[a.city][i];
//                a.city=v;
//                a.cost=d[v];

            }

        }

    }

}
//void func(ll v)
//{
//    if(v==-1)
//        return ;
//    ll u=path[v];
//    func(u);
//    cout<<v<<" ";
//}
#define PB push_back
int main()
{
    ll n,e,u,v,w;
    cin>>n>>e;
    for(ll i=0; i<e; i++)
    {
        cin>>u>>v>>w;
        G[u].push_back(v);
        G[v].push_back(u);
        E[u].PB(i+1);
        E[v].PB(i+1);
        edge[i+1][0]=u,edge[i+1][1]=v,edge[i+1][2]=w;
        dis[u].push_back(w);
        dis[v].push_back(w);

    }
    int src;
    cin>>src;
    djs(src);
    int ans=0;
    for(int i=1; i<=n; i++)
        if(path[i]!=-1)
        {
            ans+=edge[path[i]][2];
        }
    cout<<ans<<"\n";
    for(int i=1; i<=n; i++)
        if(path[i]!=-1)
        {
            cout<<path[i]<<" ";
//            ans+=edge[path[i]][2];
        }
//    vector<int>V;
//    for(int i=1; i<=n; i++)
//        if(path[i]!=-1)
//        {
//            ans+=cst[i][path[i]];
//
//        V.push_back(MP[i][path[i]]);
//        }
//        cout<<ans<<"\n";
//        sort(V.begin(),V.end());
//        for(int i=0;i<V.size();i++)
//            cout<<V[i]<<" ";
//   ll ans=djs(1,n);
//   if(ans==-1)
//    cout<<ans<<endl;
//    else
//    {
//        func(n);
//        puts("");
//    }

}


#include <bits/stdc++.h>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M)
{
    LL ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

vector < LL > vc[300001], vp[300001],cs[300001];
LL edge[300001][3], dis[300001], res[300001];
priority_queue < pair<LL,LL>, vector<pair<LL,LL> >, greater<pair<LL,LL> > >pq;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    REP(i, m)
    {

        int x, y, v;
        cin >> x >> y >> v;
        vc[x].pb(y);
        vc[y].pb(x);
        cs[x].pb(v);
        cs[y].pb(v);
        vp[x].pb(i);
        vp[y].pb(i);
        edge[i][0] = x;
        edge[i][1] = y;
        edge[i][2] = v;
    }
    int u;
    cin >> u;
   for(int i=0;i<300005;i++)
    dis[i]=1ll<<50;
    dis[u] = 0;
    pq.push(mp(0, u));
    memset(res, -1, sizeof res);
    while(!pq.empty())
    {
        pair < LL, LL > p = pq.top();
        pq.pop();
        int u=p.yy;
        if(dis[u]!=p.xx)
        {
           // cout<<"PORN : "<<dis[u]<<" "<<p.xx;
           // for(;;);
           continue;

        }
        REP(i, vc[u].size())
        {
            int v=vc[u][i];
            if(dis[v] > dis[u] + cs[u][i])
            {
                dis[v] = dis[u] + cs[u][i];
                res[v] = vp[u][i];
                pq.push(mp(dis[v], v));
            }
            else if(dis[v]==dis[u] + cs[u][i])
            {
//                if(edge[ vp[p.yy][i] ][2] <= edge[ res[ vc[p.yy][i] ] ][2])
                {
                    res[v] = vp[u][i];
                }
            }
        }
    }
    LL sum = 0;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        sum += edge[ res[i] ][2];
    }
    cout << sum << endl;
    FOR(i, 1, n+1)
    {
        if(res[i] == -1) continue;
        cout << res[i]+1 << " ";
    }
    cout << endl;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define ll long long
#define inf (10e12)+5
#define maxi 100005
using namespace std;
struct node
{
    ll city,cost;
    bool operator <(const node& p)const
    {
        return cost>p.cost;
    }
};

vector<ll>G[maxi],dis[maxi];
ll d[maxi];
ll path[maxi];
map<int,map<int,int> > MP,cst;
ll djs(ll src)
{
    for(ll i=0; i<maxi; i++)
        d[i]=inf,path[i]=-1;

    d[src]=0;
    node a;
    a.city=src,a.cost=0;
    priority_queue<node>Q;
    Q.push(a);
    while(!Q.empty())
    {
        a=Q.top();
        Q.pop();
        ll u=a.city;

        for(ll i=0; i<G[u].size(); i++)
        {

            ll v=G[u][i];
            //  cout<<v<<" ";
            //cout<<d[u]<<" "<<dis[u][i]<<endl;
            if(d[u]+dis[u][i]<d[v])
            {
                //puts("ffffffffff");

                d[v]=d[u]+dis[u][i];
                path[v]=u;
                a.city=v;
                a.cost=d[v];
                Q.push(a);

            }
            else if(d[v]==dis[u][i]+d[u])
            {
                path[v]=u;
//                a.city=v;
//                a.cost=d[v];

            }

        }

    }
//    for(int i=)
//    return -1;
}
//void func(ll v)
//{
//    if(v==-1)
//        return ;
//    ll u=path[v];
//    func(u);
//    cout<<v<<" ";
//}

int main()
{
    ll n,e,u,v,w;
    cin>>n>>e;
    for(ll i=0; i<e; i++)
    {
        cin>>u>>v>>w;
        G[u].push_back(v);
        G[v].push_back(u);
        dis[u].push_back(w);
        dis[v].push_back(w);
        MP[u][v]=i+1;
        MP[v][u]=i+1;
        cst[u][v]=w;
        cst[v][u]=w;

    }
    int src;
    cin>>src;
    djs(src);
    int ans=0;
    vector<int>V;
    for(int i=1; i<=n; i++)
        if(path[i]!=-1)
        {
            ans+=cst[i][path[i]];

        V.push_back(MP[i][path[i]]);
        }
        cout<<ans<<"\n";
        sort(V.begin(),V.end());
        for(int i=0;i<V.size();i++)
            cout<<V[i]<<" ";
//   ll ans=djs(1,n);
//   if(ans==-1)
//    cout<<ans<<endl;
//    else
//    {
//        func(n);
//        puts("");
//    }

}


#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#define ll long long
#define x first
#define y second
using namespace std;
const ll INF = 1e17;
const int MAX = 3*100*1000+100;
vector<ll> adj[MAX], w[MAX], nu[MAX];
set<pair<ll, int> > s;
ll d[MAX], p[MAX], we[MAX], cnt=0;
void dijkstra(int n)
{
    for (int i = 0; i < MAX; i++){
        d[i] = INF;
        we[i] = INF;
    }
    s.insert(make_pair(0, n));
    d[n] = 0;
    while(!s.empty())
    {
        ll v = s.begin()->y;
        s.erase(s.begin());
        for (int i = 0; i < adj[v].size(); i++)
        {
            ll u = adj[v][i];
            ll y = w[v][i];
            if (d[u] > d[v] + y)
            {
                p[u] = v;
                we[u] = y;
                s.erase(make_pair(d[u], u));
                d[u] = d[v] + y;
                s.insert(make_pair(d[u],u));
            }
            else {
                if(d[u] == d[v] + y){
                    if(y < we[u]){
                        p[u] = v;
                        we[u] = y;
                    }
                }
            }
        }
    }
}
ll ans[MAX];
main()
{
    ll n, m, u, t=0;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back(b);
        adj[b].push_back(a);
        w[a].push_back(c);
        w[b].push_back(c);
        nu[a].push_back(i+1);
        nu[b].push_back(i+1);
    }
    cin >> u;
    dijkstra(u);
    for(int i=1; i<=n; i++){
        if(i==u)continue;
        for(int j=0; j<adj[i].size(); j++){
            if (p[i] == adj[i][j]){
                ans[t++] = nu[i][j];
                cnt+=w[i][j];
                break;
            }
        }
    }
    cout << cnt << endl;
    for(int i=0; i<t; i++){
        cout << ans[i] << " ";
    }
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#define ll long long
#define x first
#define y second
using namespace std;
const ll INF = 1e12;
const int MAX = 3*100*1000+100;
vector<ll> adj[MAX], w[MAX], nu[MAX];
set<pair<ll, int> > s;
ll d[MAX], p[MAX], we[MAX], cnt=0, ans[MAX];
void dijkstra(int n)
{
    for (int i = 0; i < MAX; i++){
        d[i] = INF;
    }
    s.insert(make_pair(0, n));
    d[n] = 0;
    while(!s.empty())
    {
        ll v = s.begin()->y;
        s.erase(s.begin());
        for (int i = 0; i < adj[v].size(); i++)
        {
            ll u = adj[v][i];
            ll y = w[v][i];
            if (d[u] > d[v] + y)
            {
                p[u] = v;
                cnt-=we[u];
                we[u] = y;
                cnt+=we[u];
                ans[u] = nu[v][i];
                s.erase(make_pair(d[u], u));
                d[u] = d[v] + y;
                s.insert(make_pair(d[u],u));
            }
            else{
                if(d[u] == d[v] + y){
                    if(y < we[u]){
                        p[u] = v;
                        cnt-=we[u];
                        we[u] = y;
                        cnt+=we[u];
                        ans[u] = nu[v][i];
                    }
                }
            }
        }
    }
}
main()
{
    ll n, m, u, t=0;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back(b);
        adj[b].push_back(a);
        w[a].push_back(c);
        w[b].push_back(c);
        nu[a].push_back(i+1);
        nu[b].push_back(i+1);
    }
    cin >> u;
    dijkstra(u);
    cout << cnt << endl;
    for(int i=1; i<=n; i++){
        if(i==u)continue;
        cout << ans[i] << " ";
    }
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#define ll long long
#define x first
#define y second
using namespace std;
const ll INF = 1e12;
const int MAX = 3*100*1000+100;
vector<ll> adj[MAX], w[MAX], nu[MAX];
set<pair<ll, int> > s;
ll d[MAX], p[MAX], we[MAX], cnt=0;
void dijkstra(int n)
{
    for (int i = 0; i < MAX; i++)
        d[i] = INF;
    s.insert(make_pair(0, n));
    d[n] = 0;
    while(!s.empty())
    {
        int v = s.begin()->y;
        s.erase(s.begin());
        for (int i = 0; i < adj[v].size(); i++)
        {
            int u = adj[v][i];
            ll y = w[v][i];
            if (d[u] > d[v] + y)
            {
                p[u] = v;
                we[u] = y;
                s.erase(make_pair(d[u], u));
                d[u] = d[v] + y;
                s.insert(make_pair(d[u],u));
            }
            else {
                if(d[u] == d[v] + y){
                    if(y < we[u]){
                        p[u] = v;
                        we[u] = y;
                    }
                }
            }
        }
    }
}
int ans[MAX];
main()
{
   int n, m, u, t=0;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back(b);
        adj[b].push_back(a);
        w[a].push_back(c);
        w[b].push_back(c);
        nu[a].push_back(i+1);
        nu[b].push_back(i+1);
    }
    cin >> u;
    dijkstra(u);
    for(int i=1; i<=n; i++){
        if(i==u)continue;
        for(int j=0; j<adj[i].size(); j++){
            if(p[i] == adj[i][j]){
                ans[t++] = nu[i][j];
                cnt+=w[i][j];
                break;
            }
        }
    }
    cout << cnt << endl;
    for(int i=0; i<t; i++){
        cout << ans[i] << " ";
    }
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#define ll long long
#define x first
#define y second
using namespace std;
const ll INF = 1e12;
const int MAX = 3*100*1000+100;
vector<ll> adj[MAX], w[MAX], nu[MAX];
set<pair<ll, int> > s;
ll d[MAX], p[MAX], we[MAX], cnt=0;
void dijkstra(int n)
{
    for (int i = 0; i < MAX; i++){
        d[i] = INF;
        we[i] = INF;
    }
    s.insert(make_pair(0, n));
    d[n] = 0;
    while(!s.empty())
    {
        ll v = s.begin()->y;
        s.erase(s.begin());
        for (int i = 0; i < adj[v].size(); i++)
        {
            ll u = adj[v][i];
            ll y = w[v][i];
            if (d[u] > d[v] + y)
            {
                p[u] = v;
                we[u] = y;
                s.erase(make_pair(d[u], u));
                d[u] = d[v] + y;
                s.insert(make_pair(d[u],u));
            }
            else {
                if(d[u] == d[v] + y){
                    if(y < we[u]){
                        p[u] = v;
                        we[u] = y;
                    }
                }
            }
        }
    }
}
ll ans[MAX];
main()
{
    ll n, m, u, t=0;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back(b);
        adj[b].push_back(a);
        w[a].push_back(c);
        w[b].push_back(c);
        nu[a].push_back(i+1);
        nu[b].push_back(i+1);
    }
    cin >> u;
    dijkstra(u);
    for(int i=1; i<=n; i++){
        if(i==u)continue;
        for(int j=0; j<adj[i].size(); j++){
            if (p[i] == adj[i][j]){
                ans[t++] = nu[i][j];
                cnt+=w[i][j];
                break;
            }
        }
    }
    cout << cnt << endl;
    for(int i=0; i<t; i++){
        cout << ans[i] << " ";
    }
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#define ll long long
#define x first
#define y second
using namespace std;
const ll INF = 1e12;
const int MAX = 3*100*1000+100;
vector<ll> adj[MAX], w[MAX], nu[MAX];
set<pair<ll, int> > s;
ll d[MAX], p[MAX], we[MAX], cnt=0;
void dijkstra(int n)
{
    for (int i = 0; i < MAX; i++)
        d[i] = INF;
    s.insert(make_pair(0, n));
    d[n] = 0;
    while(!s.empty())
    {
        int v = s.begin()->y;
        s.erase(s.begin());
        for (int i = 0; i < adj[v].size(); i++)
        {
            int u = adj[v][i];
            ll y = w[v][i];
            if (d[u] > d[v] + y)
            {
                p[u] = v;
                we[u] = y;
                s.erase(make_pair(d[u], u));
                d[u] = d[v] + y;
                s.insert(make_pair(d[u],u));
            }
            else {
                if(d[u] == d[v] + y){
                    if(y < we[u]){
                        p[u] = v;
                        we[u] = y;
                    }
                }
            }
        }
    }
}
ll ans[MAX];
main()
{
    ll n, m, u, t=0;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back(b);
        adj[b].push_back(a);
        w[a].push_back(c);
        w[b].push_back(c);
        nu[a].push_back(i+1);
        nu[b].push_back(i+1);
    }
    cin >> u;
    dijkstra(u);
    for(int i=1; i<=n; i++){
        if(i==u)continue;
        for(int j=0; j<adj[i].size(); j++){
            if(p[i] == adj[i][j]){
                ans[t++] = nu[i][j];
                cnt+=w[i][j];
                break;
            }
        }
    }
    cout << cnt << endl;
    for(int i=0; i<t; i++){
        cout << ans[i] << " ";
    }
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#define ll long long
#define x first
#define y second
using namespace std;
const ll INF = 1e12;
const int MAX = 3*100*1000+100;
vector<ll> adj[MAX], w[MAX], nu[MAX];
set<pair<ll, int> > s;
ll d[MAX], p[MAX], we[MAX], cnt=0;
void dijkstra(int n)
{
    for (int i = 0; i < MAX; i++){
        d[i] = INF;
        we[i] = INF;
    }
    s.insert(make_pair(0, n));
    d[n] = 0;
    while(!s.empty())
    {
        ll v = s.begin()->y;
        s.erase(s.begin());
        for (int i = 0; i < adj[v].size(); i++)
        {
            ll u = adj[v][i];
            ll y = w[v][i];
            if (d[u] > d[v] + y)
            {
                p[u] = v;
                we[u] = y;
                s.erase(make_pair(d[u], u));
                d[u] = d[v] + y;
                s.insert(make_pair(d[u],u));
            }
            else{
                if(d[u] == d[v] + y){
                    if(y < we[u]){
                        p[u] = v;
                        we[u] = y;
                    }
                }
            }
        }
    }
}
ll ans[MAX];
main()
{
    ll n, m, u, t=0;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back(b);
        adj[b].push_back(a);
        w[a].push_back(c);
        w[b].push_back(c);
        nu[a].push_back(i+1);
        nu[b].push_back(i+1);
    }
    cin >> u;
    dijkstra(u);
    for(int i=1; i<=n; i++){
        if(i==u)continue;
        for(int j=0; j<adj[i].size(); j++){
            if (p[i] == adj[i][j]){
                ans[t++] = nu[i][j];
                cnt+=w[i][j];
                break;
            }
        }
    }
    cout << cnt << endl;
    sort(ans, ans+t);
    for(int i=0; i<t; i++){
        cout << ans[i] << " ";
    }
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#define ll long long
#define x first
#define y second
using namespace std;
const ll INF = 1e12;
const int MAX = 3*100*1000+100;
vector<ll> adj[MAX], w[MAX], nu[MAX];
set<pair<ll, int> > s;
ll d[MAX], p[MAX], we[MAX], cnt=0;
void dijkstra(int n)
{
    for (int i = 0; i < MAX; i++){
        d[i] = INF;
        we[i] = INF;
    }
    s.insert(make_pair(0, n));
    d[n] = 0;
    while(!s.empty())
    {
        ll v = s.begin()->y;
        s.erase(s.begin());
        for (int i = 0; i < adj[v].size(); i++)
        {
            ll u = adj[v][i];
            ll y = w[v][i];
            if (d[u] > d[v] + y)
            {
                p[u] = v;
                we[u] = y;
                s.erase(make_pair(d[u], u));
                d[u] = d[v] + y;
                s.insert(make_pair(d[u],u));
            }
            else{
                if(d[u] == d[v] + y){
                    if(y < we[u]){
                        p[u] = v;
                        we[u] = y;
                    }
                }
            }
        }
    }
}
ll ans[MAX];
main()
{
    ll n, m, u, t=0;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back(b);
        adj[b].push_back(a);
        w[a].push_back(c);
        w[b].push_back(c);
        nu[a].push_back(i+1);
        nu[b].push_back(i+1);
    }
    cin >> u;
    dijkstra(u);
    for(int i=1; i<=n; i++){
        if(i==u)continue;
        cnt+=we[i];
        for(int j=0; j<adj[i].size(); j++){
            if (p[i] == adj[i][j]){
                ans[t++] = nu[i][j];
                break;
            }
        }
    }
    cout << cnt << endl;
    sort(ans, ans+t);
    for(int i=0; i<t; i++){
        cout << ans[i] << " ";
    }
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#define ll long long
#define x first
#define y second
using namespace std;
const ll INF = 1e12;
const int MAX = 3*100*1000+100;
vector<ll> adj[MAX], w[MAX], nu[MAX];
set<pair<ll, int> > s;
ll d[MAX], p[MAX], we[MAX];
void dijkstra(int n)
{
    for (int i = 0; i < MAX; i++)
        d[i] = INF;
    s.insert(make_pair(0, n));
    d[n] = 0;
    while(!s.empty())
    {
        int v = s.begin()->y;
        s.erase(s.begin());
        for (int i = 0; i < adj[v].size(); i++)
        {
            int u = adj[v][i];
            ll y = w[v][i];
            if (d[u] > d[v] + y)
            {
                p[u] = v;
                we[u] = y;
                s.erase(make_pair(d[u], u));
                d[u] = d[v] + y;
                s.insert(make_pair(d[u],u));
            }
            else {
                if(d[u] == d[v] + y){
                    if(y < we[u]){
                        p[u] = v;
                        we[u] = y;
                    }
                }
            }
        }
    }
}
int ans[MAX];
main()
{
   int n, m, u, t=0;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back(b);
        adj[b].push_back(a);
        w[a].push_back(c);
        w[b].push_back(c);
        nu[a].push_back(i+1);
        nu[b].push_back(i+1);
    }
    cin >> u;
    dijkstra(u);
    for(int i=1; i<=n; i++){
        if(i==u)continue;
        for(int j=0; j<adj[i].size(); j++){
            if(p[i] == adj[i][j]){
                ans[t++] = nu[i][j];
                break;
            }
        }
    }
    for(int i=0; i<n; i++){
        if(i==u-1)continue;
        cout << ans[i] << " ";
    }
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#define ll long long
#define x first
#define y second
using namespace std;
const ll INF = 1e12;
const int MAX = 3*100*1000+100;
vector<ll> adj[MAX], w[MAX], nu[MAX];
set<pair<ll, int> > s;
ll d[MAX], p[MAX], we[MAX], cnt=0;
void dijkstra(int n)
{
    for (int i = 0; i < MAX; i++)
        d[i] = INF;
    s.insert(make_pair(0, n));
    d[n] = 0;
    while(!s.empty())
    {
        int v = s.begin()->y;
        s.erase(s.begin());
        for (int i = 0; i < adj[v].size(); i++)
        {
            int u = adj[v][i];
            ll y = w[v][i];
            if (d[u] > d[v] + y)
            {
                p[u] = v;
                we[u] = y;
                s.erase(make_pair(d[u], u));
                d[u] = d[v] + y;
                s.insert(make_pair(d[u],u));
            }
            else {
                if(d[u] == d[v] + y){
                    if(y < we[u]){
                        p[u] = v;
                        we[u] = y;
                    }
                }
            }
        }
    }
}
int ans[MAX];
main()
{
   int n, m, u, t=0;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back(b);
        adj[b].push_back(a);
        w[a].push_back(c);
        w[b].push_back(c);
        nu[a].push_back(i+1);
        nu[b].push_back(i+1);
    }
    cin >> u;
    dijkstra(u);
    for(int i=1; i<=n; i++){
        if(i==u)continue;
        for(int j=0; j<adj[i].size(); j++){
            if(p[i] == adj[i][j]){
                ans[t++] = nu[i][j];
                cnt+=w[i][j];
                break;
            }
        }
    }
    cout << cnt << endl;
    for(int i=0; i<n; i++){
        if(i==u-1)continue;
        cout << ans[i] << " ";
    }
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define N 300005
ll MOD=1e9+7;
ll MAX=1e17;
si ans;
vector< vector< pair<int,pair<int,int> > > > v(N);bool visited[N];int start,dist[N],last[N],last2[N],w[N];
void dijkstra(){
	set<pair<int,int> > s;
	rep(i,N) dist[i]=INT_MAX;
	dist[start]=0;
	s.insert(mp(0,start));
	while(!s.empty()){
		pii x=*(s.begin());
		s.erase(s.begin());
		rep(i,v[x.se].size()){
		//	cout<<dist[v[x.se][i].fi]<<" "<<dist[x.se]<<" "<<v[x.se][i].se.fi<<endl;
			if(dist[v[x.se][i].fi]>=dist[x.se]+v[x.se][i].se.fi){
		//cout<<"HI";
				if(last[v[x.se][i].fi]!=0 && v[x.se][i].fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				ans.insert(v[x.se][i].se.se);
				ans.erase(v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se);
				last[v[x.se][i].fi]=x.se;
				last2[v[x.se][i].fi]=i;
			}
				if(dist[v[x.se][i].fi]==INT_MAX) s.erase(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
				dist[v[x.se][i].fi]=dist[x.se]+v[x.se][i].se.fi;
				s.insert(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
			}
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
	int n,m;cin>>n>>m;
	rep(i,m){
		int x,y,z;cin>>x>>y>>z;
		v[x].pb(mp(y,mp(z,i+1)));v[y].pb(mp(x,mp(z,i+1)));w[i+1]=z;
	}
	cin>>start;
	dijkstra();int answer=0;
	tr(it,ans){
		answer+=w[*it];
	}
	cout<<answer<<endl;
	tr(it,ans) cout<<*it<<" ";
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define N 300005
ll MOD=1e9+7;
ll MAX=1e17;
set<ll> ans;
vector< vector< pair<ll,pair<ll,ll> > > > v(N);bool visited[N];ll start,dist[N],last[N],last2[N],w[N];
void dijkstra(){
	set<pair<ll,ll> > s;
	rep(i,N) dist[i]=1e17;
	dist[start]=0;
	s.insert(mp(0,start));
	while(!s.empty()){
		pii x=*(s.begin());
		s.erase(s.begin());
		rep(i,v[x.se].size()){
		//	cout<<dist[v[x.se][i].fi]<<" "<<dist[x.se]<<" "<<v[x.se][i].se.fi<<endl;
			if(dist[v[x.se][i].fi]>=dist[x.se]+v[x.se][i].se.fi){
		//cout<<"HI";
				if(last[v[x.se][i].fi]!=0 && v[x.se][i].se.fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				ans.erase(v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se);
			}
				if(last[v[x.se][i].fi]==0 or v[x.se][i].se.fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				ans.insert(v[x.se][i].se.se);
				last[v[x.se][i].fi]=x.se;
				last2[v[x.se][i].fi]=i;
			}
				if(dist[v[x.se][i].fi]==INT_MAX) s.erase(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
				dist[v[x.se][i].fi]=dist[x.se]+v[x.se][i].se.fi;
				s.insert(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
			}
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
	ll n,m;cin>>n>>m;
	rep(i,m){
		ll x,y,z;cin>>x>>y>>z;
		v[x].pb(mp(y,mp(z,i+1)));v[y].pb(mp(x,mp(z,i+1)));w[i+1]=z;
	}
	cin>>start;
	dijkstra();ll answer=0;
	tr(it,ans){
		answer+=w[*it];
	}
	cout<<answer<<endl;
	tr(it,ans) cout<<*it<<" ";
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define N 300005
ll MOD=1e9+7;
ll MAX=1e17;
si ans;
vector< vector< pair<ll,pair<ll,ll> > > > v(N);bool visited[N];ll start,dist[N],last[N],last2[N],w[N];
void dijkstra(){
	set<pair<ll,ll> > s;
	rep(i,N) dist[i]=INT_MAX;
	dist[start]=0;
	s.insert(mp(0,start));
	while(!s.empty()){
		pii x=*(s.begin());
		s.erase(s.begin());
		rep(i,v[x.se].size()){
		//	cout<<dist[v[x.se][i].fi]<<" "<<dist[x.se]<<" "<<v[x.se][i].se.fi<<endl;
			if(dist[v[x.se][i].fi]>=dist[x.se]+v[x.se][i].se.fi){
		//cout<<"HI";
				if(last[v[x.se][i].fi]!=0 && v[x.se][i].se.fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				ans.erase(v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se);
			}
				if(last[v[x.se][i].fi]==0 or v[x.se][i].se.fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				ans.insert(v[x.se][i].se.se);
				last[v[x.se][i].fi]=x.se;
				last2[v[x.se][i].fi]=i;
			}
				if(dist[v[x.se][i].fi]==INT_MAX) s.erase(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
				dist[v[x.se][i].fi]=dist[x.se]+v[x.se][i].se.fi;
				s.insert(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
			}
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
	ll n,m;cin>>n>>m;
	rep(i,m){
		ll x,y,z;cin>>x>>y>>z;
		v[x].pb(mp(y,mp(z,i+1)));v[y].pb(mp(x,mp(z,i+1)));w[i+1]=z;
	}
	cin>>start;
	dijkstra();ll answer=0;
	tr(it,ans){
		answer+=w[*it];
	}
	cout<<answer<<endl;
	tr(it,ans) cout<<*it<<" ";
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define N 300005
ll MOD=1e9+7;
ll MAX=1e17;
//set<ll> ans;
vector< vector< pair<ll,pair<ll,ll> > > > v(N);bool visited[N],pres[N];ll start,dist[N],last[N],last2[N],w[N],answer;
void dijkstra(){
	set<pair<ll,ll> > s;
	rep(i,N) dist[i]=1e17;
	dist[start]=0;
	s.insert(mp(0,start));
	while(!s.empty()){
		pii x=*(s.begin());
		s.erase(s.begin());
		rep(i,v[x.se].size()){
		//	cout<<dist[v[x.se][i].fi]<<" "<<dist[x.se]<<" "<<v[x.se][i].se.fi<<endl;
			if(dist[v[x.se][i].fi]>=dist[x.se]+v[x.se][i].se.fi){
		//cout<<"HI";
				if(last[v[x.se][i].fi]!=0 && v[x.se][i].se.fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				//ans.erase(v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se);
				pres[v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se]=false;answer-=w[v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se];
			}
				if(last[v[x.se][i].fi]==0 or v[x.se][i].se.fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				//ans.insert(v[x.se][i].se.se);
				pres[v[x.se][i].se.se]=true;
				answer+=w[v[x.se][i].se.se];
				last[v[x.se][i].fi]=x.se;
				last2[v[x.se][i].fi]=i;
			}
				if(dist[v[x.se][i].fi]==1e17) s.erase(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
				dist[v[x.se][i].fi]=dist[x.se]+v[x.se][i].se.fi;
				s.insert(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
			}
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
	ll n,m;cin>>n>>m;
	rep(i,m){
		ll x,y,z;cin>>x>>y>>z;
		v[x].pb(mp(y,mp(z,i+1)));v[y].pb(mp(x,mp(z,i+1)));w[i+1]=z;
	}
	cin>>start;
	dijkstra();
	cout<<answer<<endl;
	rep(i,N) if(pres[i]) cout<<i<<" ";
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define N 300005
ll MOD=1e9+7;
ll MAX=1e17;
si ans;
vector< vector< pair<int,pair<int,int> > > > v(N);bool visited[N];int start,dist[N],last[N],last2[N],w[N];
void dijkstra(){
	set<pair<int,int> > s;
	rep(i,N) dist[i]=INT_MAX;
	dist[start]=0;
	s.insert(mp(0,start));
	while(!s.empty()){
		pii x=*(s.begin());
		s.erase(s.begin());
		rep(i,v[x.se].size()){
		//	cout<<dist[v[x.se][i].fi]<<" "<<dist[x.se]<<" "<<v[x.se][i].se.fi<<endl;
			if(dist[v[x.se][i].fi]>=dist[x.se]+v[x.se][i].se.fi){
		//cout<<"HI";
				if(last[v[x.se][i].fi]!=0 && v[x.se][i].fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				ans.erase(v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se);
			}
				if(last[v[x.se][i].fi]==0 or v[x.se][i].fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				ans.insert(v[x.se][i].se.se);
				last[v[x.se][i].fi]=x.se;
				last2[v[x.se][i].fi]=i;
			}
				if(dist[v[x.se][i].fi]==INT_MAX) s.erase(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
				dist[v[x.se][i].fi]=dist[x.se]+v[x.se][i].se.fi;
				s.insert(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
			}
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
	int n,m;cin>>n>>m;
	rep(i,m){
		int x,y,z;cin>>x>>y>>z;
		v[x].pb(mp(y,mp(z,i+1)));v[y].pb(mp(x,mp(z,i+1)));w[i+1]=z;
	}
	cin>>start;
	dijkstra();int answer=0;
	tr(it,ans){
		answer+=w[*it];
	}
	cout<<answer<<endl;
	tr(it,ans) cout<<*it<<" ";
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define N 300005
ll MOD=1e9+7;
ll MAX=1e17;
si ans;
vector< vector< pair<int,pair<int,int> > > > v(N);bool visited[N];int start,dist[N],last[N],last2[N],w[N];
void dijkstra(){
	set<pair<int,int> > s;
	rep(i,N) dist[i]=INT_MAX;
	dist[start]=0;
	s.insert(mp(0,start));
	while(!s.empty()){
		pii x=*(s.begin());
		s.erase(s.begin());
		rep(i,v[x.se].size()){
		//	cout<<dist[v[x.se][i].fi]<<" "<<dist[x.se]<<" "<<v[x.se][i].se.fi<<endl;
			if(dist[v[x.se][i].fi]>=dist[x.se]+v[x.se][i].se.fi){
		//cout<<"HI";
				ans.insert(v[x.se][i].se.se);
				if(last[v[x.se][i].fi]!=0) ans.erase(v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se);
				last[v[x.se][i].fi]=x.se;
				last2[v[x.se][i].fi]=i;
				if(dist[v[x.se][i].fi]==INT_MAX) s.erase(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
				dist[v[x.se][i].fi]=dist[x.se]+v[x.se][i].se.fi;
				s.insert(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
			}
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
	int n,m;cin>>n>>m;
	rep(i,m){
		int x,y,z;cin>>x>>y>>z;
		v[x].pb(mp(y,mp(z,i+1)));v[y].pb(mp(x,mp(z,i+1)));w[i+1]=z;
	}
	cin>>start;
	dijkstra();int answer=0;
	tr(it,ans){
		answer+=w[*it];
	}
	cout<<answer<<endl;
	tr(it,ans) cout<<*it<<" ";
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define N 300005
ll MOD=1e9+7;
ll MAX=1e17;
//set<ll> ans;
vector< vector< pair<ll,pair<ll,ll> > > > v(N);bool visited[N],pres[N];ll start,dist[N],last[N],last2[N],w[N],answer;
void dijkstra(){
	set<pair<ll,ll> > s;
	rep(i,N) dist[i]=1e17;
	dist[start]=0;
	s.insert(mp(0,start));
	while(!s.empty()){
		pii x=*(s.begin());
		s.erase(s.begin());
		rep(i,v[x.se].size()){
			if(dist[v[x.se][i].fi]>dist[x.se]+v[x.se][i].se.fi){
				if(last[v[x.se][i].fi]!=0){
					pres[v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se]=false;answer-=w[v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se];
				}
				last[v[x.se][i].fi]=x.se;last2[v[x.se][i].fi]=i;pres[v[x.se][i].se.se]=true;
				if(dist[v[x.se][i].fi]!=1e17) s.erase(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
				dist[v[x.se][i].fi]=dist[x.se]+v[x.se][i].se.fi;answer+=w[v[x.se][i].se.se];
				s.insert(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
			}
			else if(dist[v[x.se][i].fi]==dist[x.se]+v[x.se][i].se.fi){
				if(last[v[x.se][i].fi]!=0 && v[x.se][i].se.fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
					pres[v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se]=false;answer-=w[v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se];
				}
				if(last[v[x.se][i].fi]==0 or v[x.se][i].se.fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
					pres[v[x.se][i].se.se]=true;
					answer+=w[v[x.se][i].se.se];
					last[v[x.se][i].fi]=x.se;
					last2[v[x.se][i].fi]=i;
				}
			}
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
	ll n,m;cin>>n>>m;
	rep(i,m){
		ll x,y,z;cin>>x>>y>>z;
		v[x].pb(mp(y,mp(z,i+1)));v[y].pb(mp(x,mp(z,i+1)));w[i+1]=z;
	}
	cin>>start;
	dijkstra();
	cout<<answer<<endl;
	rep(i,N) if(pres[i]) cout<<i<<" ";
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define N 300005
ll MOD=1e9+7;
ll MAX=1e17;
si ans;
vector< vector< pair<int,pair<int,int> > > > v(N);bool visited[N];int start,dist[N],last[N],last2[N],w[N];
void dijkstra(){
	set<pair<int,int> > s;
	rep(i,N) dist[i]=INT_MAX;
	dist[start]=0;
	s.insert(mp(0,start));
	while(!s.empty()){
		pii x=*(s.begin());
		s.erase(s.begin());
		rep(i,v[x.se].size()){
		//	cout<<dist[v[x.se][i].fi]<<" "<<dist[x.se]<<" "<<v[x.se][i].se.fi<<endl;
			if(dist[v[x.se][i].fi]>=dist[x.se]+v[x.se][i].se.fi){
		//cout<<"HI";
				if(last[v[x.se][i].fi]!=0 && v[x.se][i].se.fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				ans.erase(v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se);
			}
				if(last[v[x.se][i].fi]==0 or v[x.se][i].se.fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				ans.insert(v[x.se][i].se.se);
				last[v[x.se][i].fi]=x.se;
				last2[v[x.se][i].fi]=i;
			}
				if(dist[v[x.se][i].fi]==INT_MAX) s.erase(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
				dist[v[x.se][i].fi]=dist[x.se]+v[x.se][i].se.fi;
				s.insert(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
			}
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
	int n,m;cin>>n>>m;
	rep(i,m){
		int x,y,z;cin>>x>>y>>z;
		v[x].pb(mp(y,mp(z,i+1)));v[y].pb(mp(x,mp(z,i+1)));w[i+1]=z;
	}
	cin>>start;
	dijkstra();int answer=0;
	tr(it,ans){
		answer+=w[*it];
	}
	cout<<answer<<endl;
	tr(it,ans) cout<<*it<<" ";
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define N 300005
ll MOD=1e9+7;
ll MAX=1e17;
//set<ll> ans;
vector< vector< pair<ll,pair<ll,ll> > > > v(N);bool visited[N],pres[N];ll start,dist[N],last[N],last2[N],w[N],answer;
void dijkstra(){
	set<pair<ll,ll> > s;
	rep(i,N) dist[i]=1e17;
	dist[start]=0;
	s.insert(mp(0,start));
	while(!s.empty()){
		pii x=*(s.begin());
		s.erase(s.begin());
		rep(i,v[x.se].size()){
		//	cout<<dist[v[x.se][i].fi]<<" "<<dist[x.se]<<" "<<v[x.se][i].se.fi<<endl;
			if(dist[v[x.se][i].fi]>=dist[x.se]+v[x.se][i].se.fi){
		//cout<<"HI";
				if(last[v[x.se][i].fi]!=0 && v[x.se][i].se.fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				//ans.erase(v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se);
				pres[v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se]=false;answer-=w[v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se];
			}
				if(last[v[x.se][i].fi]==0 or v[x.se][i].se.fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				//ans.insert(v[x.se][i].se.se);
				pres[v[x.se][i].se.se]=true;
				answer+=w[v[x.se][i].se.se];
				last[v[x.se][i].fi]=x.se;
				last2[v[x.se][i].fi]=i;
			}
				if(dist[v[x.se][i].fi]==INT_MAX) s.erase(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
				dist[v[x.se][i].fi]=dist[x.se]+v[x.se][i].se.fi;
				s.insert(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
			}
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
	ll n,m;cin>>n>>m;
	rep(i,m){
		ll x,y,z;cin>>x>>y>>z;
		v[x].pb(mp(y,mp(z,i+1)));v[y].pb(mp(x,mp(z,i+1)));w[i+1]=z;
	}
	cin>>start;
	dijkstra();
	cout<<answer<<endl;
	rep(i,N) if(pres[i]) cout<<i<<" ";
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define N 300005
ll MOD=1e9+7;
ll MAX=1e17;
si ans;
vector< vector< pair<int,pair<int,int> > > > v(N);bool visited[N];int start,dist[N],last[N],last2[N],w[N];
void dijkstra(){
	set<pair<int,int> > s;
	rep(i,N) dist[i]=INT_MAX;
	dist[start]=0;
	s.insert(mp(0,start));
	while(!s.empty()){
		pii x=*(s.begin());
		s.erase(s.begin());
		rep(i,v[x.se].size()){
		//	cout<<dist[v[x.se][i].fi]<<" "<<dist[x.se]<<" "<<v[x.se][i].se.fi<<endl;
			if(dist[v[x.se][i].fi]>=dist[x.se]+v[x.se][i].se.fi){
		//cout<<"HI";
				ans.insert(v[x.se][i].se.se);
				if(last[v[x.se][i].fi]!=0 && v[x.se][i].fi<v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.fi){
				ans.erase(v[last[v[x.se][i].fi]][last2[v[x.se][i].fi]].se.se);
				last[v[x.se][i].fi]=x.se;
				last2[v[x.se][i].fi]=i;
			}
				if(dist[v[x.se][i].fi]==INT_MAX) s.erase(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
				dist[v[x.se][i].fi]=dist[x.se]+v[x.se][i].se.fi;
				s.insert(mp(dist[v[x.se][i].fi],v[x.se][i].fi));
			}
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
	int n,m;cin>>n>>m;
	rep(i,m){
		int x,y,z;cin>>x>>y>>z;
		v[x].pb(mp(y,mp(z,i+1)));v[y].pb(mp(x,mp(z,i+1)));w[i+1]=z;
	}
	cin>>start;
	dijkstra();int answer=0;
	tr(it,ans){
		answer+=w[*it];
	}
	cout<<answer<<endl;
	tr(it,ans) cout<<*it<<" ";
}