// Arup Guha
// 7/23/2025
// Solution to Kattis Problem: Big Truck
// Illustrates Dijkstra's Algorithm.

import java.util.*;

public class bigtruck_dijkstras {

	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.
		ArrayList<edge>[] g = new ArrayList[n];
		for (int i=0; i<n; i++)
			g[i] = new ArrayList<edge>();
		
		// 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();
			g[u].add( new edge( new value(w, goodies[v]), v));
			g[v].add( new edge( new value(w, goodies[u]), u));
		}
		
		// Run Dijkstra's
		value[] res = dijkstras(g, 0);
		value best = res[n-1];
				
		// This is what they want.
		if (best.dist > 10001)
			System.out.println("impossible");
		else
			System.out.println(best.dist+" "+(best.goodies+goodies[0]));
	}
	
	public static value[] dijkstras(ArrayList<edge>[] g, int s) {
	
		// Set up distance array for Dijkstras.
		int n = g.length;
		value[] dist = new value[n];
		for (int i=0; i<n; i++) dist[i] = new value(NOEDGE, 0);
		dist[s] = new value(0, 0);
		
		PriorityQueue<edge> pq = new PriorityQueue<edge>();
		pq.offer(new edge(dist[s],s));
		
		boolean[] used = new boolean[n];
		int numDone = 0;
		
		// Run Dijkstra's until we're done.
		while (pq.size() > 0 && numDone < n) {
		
			// Get next estimate.
			edge cur = pq.poll();
			
			// We already have this shortest distance.
			if (used[cur.to]) continue;
			
			// Mark this shortest distance and save it.
			used[cur.to] = true;
			dist[cur.to] = cur.v;
			numDone++;
			
			// try adding edges that leave cur.to to the priority queue.
			for (edge next: g[cur.to]) {
				value tmp = cur.v.add(next.v);
				if (tmp.compareTo(dist[next.to]) < 0) {
					dist[next.to] = tmp;
					pq.offer(new edge(tmp, next.to));
				}
			}
		
		}
		
		return dist;
	}
}

class edge implements Comparable<edge> {

	public value v;
	public int to;
	
	public edge(value myv, int where) {
		v = myv;
		to = where;
	}
	
	public int compareTo(edge other) {
		return this.v.compareTo(other.v);
	}
}

// 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);
	}
}