#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<algorithm>
#include<map>
#include<cstring>
#include<set>
using namespace std;
const int maxn = 501;
const int inf = 10000000;
int d[maxn], minneed = inf, minback = inf;
int cp, n,qs,m;
bool vis[maxn] = { false };
int G[maxn][maxn], weight[maxn];
vector<int>pre[maxn];
vector<int>tempPath, path;
void djs(int s)
{
fill(d, d + maxn, inf);
d[s] = 0;
for (int i = 0; i <= n; i++)
{
int u = -1, mins = inf;
for (int j = 0; j <= n; j++)
{
if (vis[j] == false && d[j] < mins)
{
u = j;
mins = d[j];
}
}
if (u == -1) return;
vis[u] = true;
for (int v = 0; v <= n; v++)
{
if (vis[v] == false && G[u][v] != inf)
{
if (d[u] + G[u][v] < d[v])
{
d[v] = d[u] + G[u][v];
pre[v].clear();
pre[v].push_back(u);
}
else if (d[u] + G[u][v] == d[v])
{
pre[v].push_back(u);
}
}
}
}
}
void dfs(int v)
{
if (v == 0)
{
tempPath.push_back(v);
int need = 0, back = 0;
for (int i = tempPath.size() - 1; i >= 0; i--)
{
int id = tempPath[i];
if (weight[id] > 0)
{
back += weight[id];
}
else
{
if (back > abs(weight[id]))
{
back -= abs(weight[id]);
}
else
{
need += abs(weight[id]) - back;
back = 0;
}
}
}
if (need < minneed)
{
minneed = need;
minback = back;
path = tempPath;
}
else if (need == minneed && back < minback)
{
minback = back;
path = tempPath;
}
tempPath.pop_back();
return;
}
tempPath.push_back(v);
for (int i = 0; i < pre[v].size(); i++)
{
dfs(pre[v][i]);
}
tempPath.pop_back();
}
int main()
{
cin>>cp>>n>>qs>> m;
int u, v;
fill(G[0], G[0] + maxn * maxn, inf);
for (int i = 1; i <= n; i++)
{
cin >> weight[i];
weight[i] -= cp / 2;
}
for (int i = 0; i < m; i++)
{
cin >> u >> v;
cin >> G[u][v];
G[v][u] = G[u][v];
}
djs(0);
dfs(qs);
cout << minneed << " ";
for (int i = path.size() - 1;i >= 0; i--)
{
cout << path[i];
if (i > 0) cout << "->";
}
cout << " " << minback << endl;
return 0;
}