当我点击提交按钮没有反应无法提交代码Ideone
我的代码:
import java.awt.Point;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringTokenizer;
class TestClass {
static int cost;
static int m;
static int dp[][];
static int graph[][];
static int vis[][];
static int first[];
static boolean fin;
public static class Batman{
int to ;
int from ;
int d;
public Batman(int to , int from , int d){
this.to = to;
this.from = from;
this.d =d;
}
}
public static int find(int x , int[] p){
if(p[x]==x) return x;
return find(p[x], p);
}
public static void union(int x , int y , int[] size , int[] p){
if(size[x]>size[y]){
p[y]=x;
size[x]++;
}else{
p[x]=y;
size[y]++;
}
}
public static void main(String args[]) throws IOException {
InputStream inputStream = System.in;
InputReader in = new InputReader(inputStream);
//Scanner in = new Scanner(new InputStreamReader(System.in));
int n = in.nextInt();
int[] Parent = new int[n];
int[] Size= new int[n];
for(int i=0;i<n;i++){
Parent[i]=i;
Size[i]=1;
}
Batman[] trees = new Batman[n-1];
int min =Integer.MAX_VALUE;
int dd=0;
for(int i=0;i<n-1;i++){
int xx = in.nextInt()-1;
int yy = in.nextInt()-1;
int d =in.nextInt();
trees[i] = new Batman(xx, yy, d);
if(xx==0 && min>d)
{
min = d;
dd=yy;
}
if(yy==0 && min>d){
min =d;
dd=xx;
}
}
Arrays.sort(trees, new Comparator<Batman>() {
public int compare(Batman a, Batman b) {
// TODO Auto-generated method stub
return a.d-b.d;
}
});
int ans=0;
if(min!=Integer.MAX_VALUE){
ans=min;
Parent[dd]=0;
Size[0]+=1;
}
for(int i=0;i<n-1;i++){
int xx = find(trees[i].from,Parent);
int yy = find(trees[i].to,Parent);
if(xx!=yy){
ans+=trees[i].d;
union(xx, yy, Size,Parent);
}
}
System.out.println(ans);
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
}
样品输入:
4
4 3 1
4 2 2
1 2 1
问题出在哪里?同样的事情发生时,我试图提交此Problem的解决方案时,我点击提交按钮没有任何反应
[为什么我不能问客户服务相关的问题?](http://meta.stackoverflow.com/a/255746) – Pshemo
请选择一个描述问题的标题。 – tnw