#include using namespace std; typedef long long ll; #define fi first #define se second const ll mod=998244353; const int N=2e5+5; ll n,m,k,z,y; int eu[N],ev[N]; ll ew[N]; ll d[N]; vector >in[N],out[N]; int sz=0; vectorg[N]; map >ban[N]; ll jp[N]; ll mn[1<<19]; void build(int id,int l,int r){ if(l==r){ mn[id]=d[in[y][l-1].se]; return; } int mid=(l+r)/2; build(id*2,l,mid); build(id*2+1,mid+1,r); mn[id]=min(mn[id*2],mn[id*2+1]); } ll qry(int id,int l,int r,int ql,int qr){ if(l>qr || r> n >> m; for(int i=1; i<=m ;i++){ int u,v;ll w;cin >> u >> v >> w; eu[i]=u;ev[i]=v;ew[i]=w; in[v].push_back({u,i}); out[u].push_back({v,i}); d[i]=1e18; } in[1].push_back({0,0}); cin >> k; for(int i=1; i<=k ;i++){ int a,b,c;cin >> a >> b >> c; ban[b][c].push_back(a); } ll res=1e18; for(int i=1; i<=n ;i++){ if(in[i].empty()) continue; y=i; sort(in[i].begin(),in[i].end()); z=in[i].size(); for(int j=0; jg; for(auto d:v){ if(jp[d]!=0) g.push_back(jp[d]); } sort(g.begin(),g.end()); int prv=0; ll cur=1e18; for(auto d:g){ if(prv+1