2015-02-04 45 views
-2

当我点击提交按钮没有反应无法提交代码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的解决方案时,我点击提交按钮没有任何反应

+1

[为什么我不能问客户服务相关的问题?](http://meta.stackoverflow.com/a/255746) – Pshemo

+0

请选择一个描述问题的标题。 – tnw

回答

1

它必须遵循的示例程序的指导方针:

/* package whatever; // don't place package name! */ 

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

/* Name of the class has to be "Main" only if the class is public. */ 
class Ideone 
{ 
    public static void main (String[] args) throws java.lang.Exception 
    { 
     // your code goes here 
    } 
} 

请确保您有正确的语言选择(例如Java或Java7)。另外,请确保您正确输入了输入:

4 
4 3 1 
4 2 2 
1 2 1 

在最后一行之后应该有下一行字符。

这里是a working version

+0

主类的名字不一定是'Ideone'。它也适用于复制粘贴OP代码而不更改任何名称:http://ideone.com/C4Wj2U – Pshemo

+0

@Pshemo已更正我的代码或只是您复制并粘贴它 – user4447943

+0

@ user4447943它是从您的问题复制粘贴,我没有编辑任何东西。 – Pshemo