#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int inf=0x3f3f3f3f;
struct node
{
int from;
int to;
int w;
int next;
}e[500505];
int head[1005];
int dist[1005];
int vis[1005],ci[1005];
int n,cont;
void add(int from,int to,int w)
{
e[cont].to=to;
e[cont].w=w;
e[cont].next=head[from];
head[from]=cont++;
}
void SPFA()
{
memset(vis,0,sizeof(vis));
memset(ci,0,sizeof(ci));
for(int i=1;i<=n;i++)dist[i]=inf;
dist[1]=0;
queue<int >s;
s.push(1);
ci[1]=1;
while(!s.empty())
{
int u=s.front();
vis[u]=0;
s.pop();
for(int i=head[u];i!=-1;i=e[i].next)
{
int v=e[i].to;
int w=e[i].w;
if(dist[v]>dist[u]+w)
{
dist[v]=dist[u]+w;
if(v==1&&dist[v]!=0)//存在环
{
printf("-1\n");
return;
}
if(vis[v]==0)
{
s.push(v);
ci[v]++;
if(ci[v]>n)
{
printf("-1\n");
return;
}
vis[v]=1;
}
}
}
}
if(dist[n]==inf)printf("-2\n");
else printf("%d\n",dist[n]);
}
int main()
{
int l,d;
while(~scanf("%d%d%d",&n,&l,&d))
{
cont=0;
memset(head,-1,sizeof(head));
int a,b,c;
while(l--)
{
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
}
while(d--)
{
scanf("%d%d%d",&a,&b,&c);
add(b,a,-c);
}
for(int i = 2;i <= n;i++)
{
add(i,i - 1,0);
}
SPFA();
}
return 0;
}
09-11
09-11
09-11