// Arup Guha
// 4/9/2024
// Solution to Kattis Problem: Big Truck
// Uses Leo Melson's idea to just store goodies as negative values.
// https://open.kattis.com/problems/bigtruck

import java.util.*;

public class bigtruck {

	final public static int NOEDGE = 1000000000;
	
	public static int n;
	public static int[] pts;

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		pts = new int[n];
		
		// Read points.
		for (int i=0; i<n; i++)
			pts[i] = stdin.nextInt();

		// Default matrix with no edges.
		int[][] adj = new int[n][n];
		for (int i=0; i<n; i++) {
			Arrays.fill(adj[i], NOEDGE);
			adj[i][i] = 0;
		}
		
		// Read in edges, when we put one in, we multiply the weight by 100000 to give it
		// "precedence." Then we subtract out the goodies at the end of that vertex.
		int numE = stdin.nextInt();
		for (int i=0; i<numE; i++) {
			int u = stdin.nextInt()-1;
			int v = stdin.nextInt()-1;
			int w = stdin.nextInt();
			adj[u][v] = 100000*w - pts[v];
			adj[v][u] = 100000*w - pts[u];
		}
		
		// Run Floyd's.
		for (int k=0; k<n; k++)
			for (int i=0; i<n; i++)
				for (int j=0; j<n; j++)
					adj[i][j] = Math.min(adj[i][j], adj[i][k]+adj[k][j]);
					
		// Can't do it.
		if (adj[0][n-1] >= NOEDGE)
			System.out.println("impossible");
		
		// Extract answer from value.
		else {
			
			// Extract # of goodies received.
			int left = 100000-adj[0][n-1]%100000;
			left %= 100000;
			
			// Here is the distance.
			int dist = (adj[0][n-1]+left)/100000;
			
			// One last hack, we need to add in the goodies at the start...
			System.out.println(dist+" "+(left+pts[0]));
		}
	}
}