// Arup Guha
// 7/23/2025
// Solution to Kattis Problem: Big Truck
// Illustrates Floyd Warshall's Algorithm.

import java.util.*;

public class bigtruck {

	final public static int NOEDGE = 1000000;

	public static void main(String[] args) {
	
		// Read in the goodies.
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int[] goodies = new int[n];
		for (int i=0; i<n; i++)
			goodies[i] = stdin.nextInt();
			
		// Create the graph.
		value[][] adj = new value[n][n];
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++)
				if (i == j) adj[i][j] = new value(0, goodies[i]);
				else adj[i][j] = new value(NOEDGE, 0);
		}
		
		// Add edges.
		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] = new value(w, goodies[v]);
			adj[v][u] = new value(w, goodies[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++)
					if (adj[i][j].compareTo(adj[i][k].add(adj[k][j])) > 0 && k != i && k != j)
						adj[i][j] = adj[i][k].add(adj[k][j]);
				
		// This is what they want.
		if (adj[0][n-1].dist > 10001)
			System.out.println("impossible");
		else
			System.out.println(adj[0][n-1].dist+" "+(adj[0][n-1].goodies+goodies[0]));
	}
}

// Instead of straight distance minimization, we are minimizing this value.
class value implements Comparable<value> {

	public int dist;
	public int goodies;
	
	public value(int d, int g) {
		dist = d;
		goodies = g;
	}
	
	public int compareTo(value other) {
		if (this.dist != other.dist)
			return this.dist - other.dist;
		return other.goodies - this.goodies;
	}
	
	public value add(value other) {
		return new value(this.dist+other.dist, this.goodies+other.goodies);
	}
}