#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> #include <stack> #include <queue> #include <vector> #include <map> #include <string> #include <iostream> using namespace std; int n; const int INF=0xfffffff; struct edge { int val;int to;int next; }e[111111]; int len;int head[11111]; void add(int from,int to,int val) { e[len].to=to;e[len].val=val;e[len].next=head[from];head[from]=len++; } int dis[11111]; int spfa(int x) { int vis[11111]; for(int i=1;i<=n;i++) vis[i]=0; for(int i=1;i<=n;i++) dis[i]=INF; vis[x]=1; dis[x]=0; queue<int> q; q.push(x); int cnt[11111]={0}; cnt[x]=1; while(!q.empty()){ int cur=q.front(); q.pop();vis[cur]=0; for(int i=head[cur];i!=-1;i=e[i].next){ int cc=e[i].to; if(dis[cc]>dis[cur]+e[i].val){ dis[cc]=dis[cur]+e[i].val; if(!vis[cc]){ cnt[cc]++;if(cnt[cc]>n) return 0; q.push(cc); vis[cc]=1; } } } } return 1; } int main() { int m,l; while(scanf("%d%d%d",&n,&m,&l)!=EOF){ len=0;memset(head,-1,sizeof(head)); for(int i= 0;i<m;i++){ int a,b,c;scanf("%d%d%d",&a,&b,&c); if(a>b) {int t=a;a=b;b=t;} add(a,b,c); } for(int i=0;i<l;i++){ int a,b,c;scanf("%d%d%d",&a,&b,&c); if(a<b){int t=a;a=b;b=t;}; add(a,b,-c); } if(!spfa(1)) printf("-1 "); else{ if(dis[n]==INF) printf("-2 "); else printf("%d ",dis[n]); } } return 0; }