#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
const int maxn=508;
int Cmax,N,Sp,M;
struct node{
int adjvex;
int times;
};
vector<node>G[maxn];
int C[maxn];
vector<int>back[maxn];
const int inf=1000000000;
bool vis[maxn]={false};
int d[maxn];
vector<int>pre[maxn];
vector<int>temppath,path;
int minneed=inf,minremain=inf;
void Dijkstra()
{
for(int i=0;i<=N;i++)
{
int u=-1,min=inf;
for(int j=0;j<=N;j++)
{
if(vis[j]==false&&d[j]<min)
{
min=d[j];
u=j;
}
}
if(u==-1)return;
vis[u]=true;
for(int j=0;j<G[u].size();j++)
{
int v=G[u][j].adjvex;
int w=G[u][j].times;
if(vis[v]==false)
{
if(d[v]>d[u]+w)
{
d[v]=d[u]+w;
//c[v]=c[u]+C[v];
pre[v].clear();
pre[v].push_back(u);
}else if(d[v]==d[u]+w)
{
pre[v].push_back(u);
}
}
}
}
}
void DFS(int v)
{
if(v==0)
{
temppath.push_back(v);
int need=0,remain=0;
for(int i=temppath.size()-1;i>=0;i--)
{
int id=temppath[i];
if(C[id]>0)
{
remain+=C[id];
}else
{
if(remain>=(-1)*C[id])
{
remain+=C[id];
}else
{
remain+=C[id];
need-=remain;
remain=0;
}
}
}
if(need<minneed)
{
minneed=need;
minremain=remain;
path=temppath;
}else if(minneed==need&&minremain>remain)
{
minremain=remain;
path=temppath;
}
temppath.pop_back();
return;
}
else
{
temppath.push_back(v);
for(int i=0;i<pre[v].size();i++)
{
DFS(pre[v][i]);
}
temppath.pop_back();
}
}
int main()
{
cin>>Cmax>>N>>Sp>>M;
for(int i=1;i<=N;i++)
{
cin>>C[i];
C[i]-=Cmax/2;
}
C[0]=0;
for(int i=0;i<M;i++)
{
int a,b,c;
cin>>a>>b>>c;
node Node;
Node.adjvex=b;
Node.times=c;
G[a].push_back(Node);
Node.adjvex=a;
G[b].push_back(Node);
}
for(int i=0;i<=N;i++)
{
d[i]=inf;
}
d[0]=0;
Dijkstra();
DFS(Sp);
cout<<minneed<<‘ ‘;
for(int i=path.size()-1;i>=0;i--)
{
cout<<path[i];
if(i==0)
{
cout<<‘ ‘;
}else
{
cout<<"->";
}
}
cout<<minremain<<endl;
return 0;
}