Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 神啊!!!!谁能告诉我为什么会Runtime Error

Posted by blackchaoxu at 2007-01-30 12:40:44 on Problem 3107
```import java.util.*;

public class Main {
static int n;
static ArrayList<Integer>[] edge;

static int[] maxSon,sonNum;

static void readIn() {
Scanner cin = new Scanner(System.in);
n = cin.nextInt();
edge = new ArrayList[n+1];
for (int i = 1; i <= n; i++)
edge[i] = new ArrayList<Integer>();
for (int i = 0; i < n-1; i++) {
int u,v;
u = cin.nextInt();
v = cin.nextInt();
}
}

static void makeTree(int p, int f) {
for (int i = 0; i < edge[p].size(); i++) {
int v = edge[p].get(i);
if (v != f) {
makeTree(v, p);
sonNum[p] += sonNum[v];
if (maxSon[p] < sonNum[v])
maxSon[p] = sonNum[v];
}
sonNum[p]++;
}
}

public static void main(String[] args) {

maxSon = new int[n+1];
sonNum = new int[n+1];
makeTree(1, 0);

ArrayList<Integer> ans = new ArrayList<Integer>();
int maxComp = n;
for (int i = 1; i <= n; i++) {
if (maxComp > Math.max(sonNum[1]-sonNum[i], maxSon[i])) {
maxComp = Math.max(sonNum[1]-sonNum[i], maxSon[i]);
ans.clear();
}else if (maxComp == Math.max(sonNum[1]-sonNum[i], maxSon[i]))
}
for (int i = 0; i < ans.size(); i++)
System.out.print(ans.get(i)+" ");
}

}
```

Followed by: