import java.util.*;class Edge{ public int to, w, next; Edge(){ } Edge(int to, int w, int next){ this.to = to; this.w = w; this.next = next; }}public class Test{ static int cnt = 0; static int n = 5; static int m = 7; static Edge[] edges = new Edge[m]; static int[] head = new int[n + 1]; static void init(){ for(int i = 0; i <= n; i++){ head[i] = -1; } cnt = 0; } static void add_edge(int u, int v, int w){ edges[cnt] = new Edge(); edges[cnt].to = v; edges[cnt].w = w; edges[cnt].next = head[u]; head[u] = cnt++; } public static void main(String[] args) { init(); int[][] inputs = {{1,2,1}, {2,3,2}, {3, 4, 3}, {1, 3, 4}, {4, 1, 5}, {1, 5, 6}, {4, 5, 7}}; for(int i = 0; i < inputs.length; i++){ add_edge(inputs[i][0], inputs[i][1], inputs[i][2]); } for(int i = 1; i <= n; i++){ for (int j = head[i]; j != -1; j = edges[j].next){ System.out.println("start=" + i + " to=" + edges[j].to + " w=" + edges[j].w); } } }}