//首先这道题是卡没有优化的迪斯特拉的。。。。然后就是数据的溢出问题。。。都开long long吧
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn=300000+10;
const ll inf=99999999999999999;
int head[maxn];
int next[2*maxn];
int to[2*maxn];
ll val[2*maxn];
int viss[maxn];
int id[2*maxn];
int ans[maxn];
int tot;
typedef long long ll;
int inline read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
struct heapnode
{
ll d;
ll u;
heapnode()
{
}
heapnode(ll d1,ll u1):d(d1),u(u1)
{
}
bool operator <(const heapnode &rhs)const
{
return d>rhs.d;
}
};
void init()
{
tot=0;
memset(head,-1,sizeof(head));
}
void inline addedge(int u,int v,ll value,int id1)
{
to[tot]=v;
val[tot]=value;
id[tot]=id1;
next[tot]=head[u];
head[u]=tot++;
}
int visit[maxn];
ll low[maxn];
int n;
void inline dista(int start)
{
memset(visit,0,sizeof(visit));
ll sum=0;
int k=0;
low[start]=0;
priority_queue<heapnode>que;
heapnode x;
x.d=0;
x.u=start;
que.push(x);
while(!que.empty())
{
heapnode x=que.top();
que.pop();
if(visit[x.u])
continue;
visit[x.u]=1;
for(int i=head[x.u];i!=-1;i=next[i])
{
int v=to[i];
if(low[v]>low[x.u]+val[i])
{
low[v]=low[x.u]+val[i];
que.push(heapnode(low[v],v));
}
}
}
}
int main()
{
int m;
init();
memset(viss,0,sizeof(viss));
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
int a,b,c;
a=(ll)read();
b=(ll)read();
c=(ll)read();
addedge(a,b,c,i);
addedge(b,a,c,i);
}
for(int i=1;i<=n;i++)
low[i]=inf;
int start;
scanf("%d",&start);
dista(start);
int k=0;
ll sum=0;
for(int i=1;i<=n;i++)
{
if(i!=start)
{
int pre=inf;
int pos;
for(int j=head[i];j!=-1;j=next[j])
{
int v=to[j];
// cout<<i<<" vvvv"<<v<<endl;
// cout<<"low[i] "<<low[i]<<" "<<low[v]<<" "<<val[j]<<endl;
if(low[v]+val[j]==low[i]&&val[j]<pre/*&&viss[id[j]]==0*/)
{
pre=val[j];
pos=id[j];
}
}
sum+=pre;
ans[k++]=pos;
//viss[pos]=1;
}
}
sort(ans,ans+k);
printf("%lld\n",sum);
for(int i=0;i<k;i++)
{
if(i!=k-1)
printf("%d ",ans[i]);
else
printf("%d\n",ans[i]);
}
return 0;
}