如题:
import java.util.*;
import java.io.*;
public class Main{
static final int MAXN = 1010;
static final int MAXM = 10100;
static final int INF = 2000000;
static int Head[] = new int[MAXN];
static int Next[] = new int[2*MAXM];
static int EV[] = new int[2*MAXM];
static int EL[] = new int[2*MAXM];
static int N, M;
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); ;
static StringTokenizer st;
//顶点的标号从1到n,无向图
public static void main(String av[])throws Exception{
N = nextInt(); M = nextInt();
for(int i = 1; i <= N; i++)Head[i] = 0;
int Num = 0;
for(int i = 0; i < M; i++){
int a, b, f;
a = nextInt(); b = nextInt(); f = nextInt();
EV[++Num] = b;EL[Num] = f;Next[Num] = Head[a];Head[a] = Num;
EV[++Num] = a;EL[Num] = f;Next[Num] = Head[b];Head[b] = Num;
}
}
private static int nextInt() throws Exception {
return Integer.parseInt(next());
}
private static String next() throws Exception {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(in.readLine());
return st.nextToken();
}
}