public static void main(String[] args) {
		try {
			BufferedReader in = null;
			if (args.length > 0) {
				in = new BufferedReader(new FileReader(args[0]));
			} else {
				in = new BufferedReader(new InputStreamReader(System.in));
			}
			// BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			ArrayList<String> input = new ArrayList<String>();
			String inp = in.readLine();
			while (inp != null) {
				input.add(inp);
				inp = in.readLine();
			}
			StringTokenizer st;
			StringTokenizer st2;
			PriorityQueue<Edge> edges = new PriorityQueue<Edge>();
			Vertex[] noder = new Vertex[input.size()];
			for (int i = 0; i < input.size(); i++) {
				st = new StringTokenizer((String) input.get(i));
				Vertex vertex = new Vertex(i);
				noder[i] = vertex;
				while (st.hasMoreTokens()) {
					st2 = new StringTokenizer(st.nextToken(), ":");
					int to = Integer.parseInt(st2.nextToken());
					int weight = Integer.parseInt(st2.nextToken());
					edges.add(new Edge (i,to,weight));
				}
			}
			System.out.println(mst(edges, noder));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}