#include using namespace std; typedef long long int ll; typedef pair P; const ll MOD=1000000007; const ll INF=10000010; const ll LINF=4000000000000000010LL; const int MAX=310; const double EPS=1e-9; int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; int main(){ int n;cin>>n; int s[51]; int d[51][51]; for(int i=0;i>s[i]; } int m;cin>>m; for(int i=0;i>a>>b>>c; d[a][b]=min(d[a][b],c); d[b][a]=min(d[b][a],c); } for(int k=0;k