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));
			}
			ArrayList<String> input = new ArrayList<String>();
			String inp = in.readLine();
			while(inp!=null){
				input.add(inp);
				inp=in.readLine();
			}
			int nodeCount = input.size();
			ArrayList<Edge> verticesList = new ArrayList<Edge>(nodeCount*3);
			StringTokenizer st;
			StringTokenizer stSplitter;
			for(int i=0;i<nodeCount;i++){
				st = new StringTokenizer((String)input.get(i));
				while(st.hasMoreTokens()){
					stSplitter = new StringTokenizer(st.nextToken(), ":");
					verticesList.add(new Edge(i, Integer.parseInt(stSplitter.nextToken()), Integer.parseInt(stSplitter.nextToken())));
				}
			}
			int verticesLen = verticesList.size();
			Edge[] vertices = new Edge[verticesLen];
			for (int i = 0; i < verticesLen; i++) {
				vertices[i] = verticesList.get(i);
			}
			Arrays.sort(vertices);
			System.out.println(new StringBuilder().append(mst(vertices, nodeCount)).toString());
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}