import java.io.*;
import java.util.*;

public class TestGen {

    static int done = 0;

    static final Random rand = new Random();
    static int[][] edge;
    static int[] p, s;    
    static int NS, NL, N;

    static void print() throws IOException  {
		done++;
		int n = N;
		//System.err.println("Generation test #" + done);
		PrintWriter out;
		out = new PrintWriter("road.in");		
		out.print(n);
		out.print(' ');
		out.print(NS);
		out.print(' ');
		out.println(NL);
		for (int i = 2; i <= n; i++) {
	    	out.print(edge[i][0]);
			out.print(' ');
			out.print(edge[i][1]);
			out.print(' ');
			out.println(edge[i][2]);									    
	    }	
		out.close();    
    }
        
    static void genSimple() throws IOException {
		PrintWriter out;
		out = new PrintWriter("../preliminary/01");
		out.println("5 3 2");
		out.print("1 2 1\n2 3 1\n3 5 1\n2 4 2");
		out.close();
    }
    

    static int randFromTo(int from, int to) {
		return rand.nextInt(to - from + 1) + from;
    }        
    static void genTree(int n, int maxW) {
    	p = new int[100100];
    	s = new int[100100];
    	edge = new int[100100][4];
    	p[1] = 1;
    	for (int i = 2; i <= n; ++i)
    		p[i] = randFromTo(1, i - 1);
    	for (int i = 2; i <= n; ++i) {
    		edge[i][0] = i;
    		edge[i][1] = p[i];
    		edge[i][2] = randFromTo(1, maxW);
    		s[i] = edge[i][2];
    	}    		
    }
    static int[] sum, len;
    static void makeGoodTest(int minN, int maxN, int maxW)  throws IOException  {
    	int n = randFromTo(minN, maxN);
    	sum = new int[100100];
    	len = new int[100100];
    	N = n;
    	genTree(n, maxW);
    	int a = randFromTo(1, n), b = randFromTo(1, n);    	
    	int v1 = a, l = 0, v2 = b;
    	while (v1 != 1) {
    		sum[p[v1]] = sum[v1] + s[v1];
    		len[p[v1]] = len[v1] + 1;
    		v1 = p[v1];
    	}
    	NS = 0; NL = 0;
		while (v2 != 1) {
			if (sum[v2] > 0) {
    			NS = sum[v1] + sum[v2];
    			NL = len[v1] + len[v2];
    			break;
    		}
    		sum[p[v2]] = sum[v2] + s[v2];
    		len[p[v2]] = len[v2] + 1;
    		v2 = p[v2];    		
    	}
    	print();
    }	
	static void makeRandomTest(int minN, int maxN, int maxW)  throws IOException {
    	int n = randFromTo(minN, maxN);
    	N = n;
    	sum = new int[100000];
    	len = new int[100000];
    	genTree(n, maxW);
    	NS = randFromTo(1, 1000000);
    	NL = randFromTo(1, n);
    	print(); 
    }
    static int pow10(int a) {
    	int ans = 1;
    	while (a --> 0)
    		ans *= 10;
    	return ans;
    }
    static int max(int a, int b) {
    	if (a > b)
    		return a;
    	return b;
    }

    public static void main(String[] args) throws IOException {
		done = 0;
		makeGoodTest(10, 100, 10000);
				
		return;
    }
}
