#include <iostream>
#include <fstream>
using namespace std;
int d,p,c,ff,s;
int a[300][300];
int i,j,k,l;
int f[300],q[1000000];
int head,tail;
int main()
{
ifstream fin("jobhunt.in");
ofstream fout("jobhunt.out");
fin>>d>>p>>c>>ff>>s;
for (i=1;i<=p;i++)
{
fin>>j>>k;
a[j][k]=-d;
}
for (i=1;i<=ff;i++)
{
fin>>j>>k>>l;
a[j][k]=l-d;
}
for (i=1;i<=c;i++)
f[i]=9999999;
q[1]=s;
f[s]=-d;
head=1;
tail=1;
while (head<=tail)
{
for (i=1;i<=c;i++)
if (a[q[head]][i]!=0)
if ((f[q[head]]+a[q[head]][i])<f[i])
{
f[i]=(f[q[head]]+a[q[head]][i]);
if (f[i]<(-c*d))
{
fout<<"-1";
fin.close();
fout.close();
return 0;
}
tail++;
q[tail]=i;
}
head++;
}
l=99999;
for (i=1;i<=c;i++)
if (f[i]<l)
l=f[i];
l=-l;
fout<<l;
fin.close();
fout.close();
return 0;
}