| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
大牛看看是怎么回事,总是显示RE
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static int prim(int a[][],int n){
int max = 0;
int i,j,k;
int low[]=new int[n];
boolean used[]=new boolean[n];
for(i=0;i<n;i++){
low[i]=a[0][i];
// used[i]=false;
}
used[0]=true;
for(i=1;i<n;i++){
j=0;
while(used[j]){
j++;
}
for(k=0;k<n;k++){
if((!used[k])&&low[k]<low[j]){
j=k;
}
}
if(low[j]>max)
max=low[j];
used[j]=true;
for(k=0;k<n;k++){
if((!used[k])&&a[j][k]<low[k]){
low[k]=a[j][k];
}
}
}
return max;
}
public static void main(String[] args) throws Exception, IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
int a[][];
int num=Integer.parseInt(in.readLine());
while(num--!=0){
int n=Integer.parseInt(in.readLine());
a=new int[n][n];
for(int index=0;index<n;index++){
String str=in.readLine();
String line[]=str.split(" ");
for(int i=0;i<n;i++){
a[index][i]=Integer.parseInt(line[i]);
}
}
System.out.println(prim(a,n));
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator