第三题:差一个排序输出,,,
import java.util.Scanner;
public class Test006 {
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
int group = scanner.nextInt();
while (group >= 1)
{
int userNum = scanner.nextInt();
int target = scanner.nextInt();
int degree = scanner.nextInt();
int[][] users = new int[userNum][userNum];
int[][] degrees = new int[userNum][userNum];
for (int j = 0; j < userNum; j++)
{
for (int k = 0; k < userNum; k++)
{
if (j == k)
{
users[j][k] = -1;
degrees[j][k] = -1;
}
else
{
users[j][k] = 0;
degrees[j][k] = 0;
}
}
}
int num = scanner.nextInt();
for (int i = 0; i < num; i++)
{
int user1 = scanner.nextInt();
int user2 = scanner.nextInt();
users[user1][user2] = users[user2][user1] = scanner.nextInt();
degrees[user1][user2] = degrees[user2][user1] = 1;
}
deal(users, degrees,target);
for (int l = 0; l < userNum; l++)
{
if (degrees[target][l] == degree)
{
System.out.print((users[target][l]) + " ");
}
}
group--;
}
}
public static void deal(int[][] array, int[][] degree, int row)
{
int rows = array.length;
for(int col = 0; col < rows;col++)
{
if(array[row][col] != -1 && array[row][col] != 0)
{
for(int j = 0 ; j < rows; j++)
{
if(array[col][j] != -1 && array[col][j] != 0 && array[row][j] == 0)
{
array[j][row] = array[row][j] = array[col][j] + array[row][col];
degree[j][row] = degree[row][j] = degree[col][j] + degree[row][col];
}
}
}
}
}