当我点击提交按钮时,没有任何事情发生
我的代码:
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的解决方案时,当我点击提交按钮没有任何反应时发生
答案 0 :(得分: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
在最后一行之后应该有一个下一行字符。