​传送门​


#include<bits/stdc++.h>
#define N 1005
#define M 20005*2
#define inf 1e15
#define LL long long
using namespace std;
int n,ml,md,vis[N],times[N]; LL dis[N];
int first[N],next[M],to[M],w[M],tot;
int read(){
int cnt=0,f=1;char ch=0;
while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
while(isdigit(ch))cnt=cnt*10+(ch-'0'),ch=getchar();
return cnt*f;
}
void add(int x,int y,int z){
next[++tot]=first[x],first[x]=tot,to[tot]=y,w[tot]=z;
}
LL spfa(){
for(int i=1;i<=n;i++) dis[i]=inf;
queue<int> q;
q.push(1); dis[1]=0,vis[1]=1;
while(!q.empty()){
int x=q.front(); q.pop(); vis[x]=0 , times[x]++;
if(times[x]>=n) return -1;
for(int i=first[x];i;i=next[i]){
int t=to[i];
if(dis[t] > dis[x] + w[i]){
dis[t] = (LL)dis[x] + w[i];
if(!vis[t]) vis[t]=1 , q.push(t);
}
}
}return dis[n]==inf ? -2 : dis[n];
}
int main(){
n=read(),ml=read(),md=read();
while(ml--) {int x=read(),y=read(),z=read(); add(x,y,z);}
while(md--) {int x=read(),y=read(),z=read(); add(y,x,-z);}
for(int i=2;i<=n;i++) add(i,i-1,0);
printf("%lld",spfa()); return 0;
}