2015-02-04 47 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