Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Xranda {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int a,b,w,n = sc.nextInt();
- int m[][] = new int[n][n];
- for (int i = 0; i < n-1; i++) {
- a = sc.nextInt();
- b= sc.nextInt();
- w = sc.nextInt();
- m[a-1][b-1] = w;
- m[b-1][a-1] = w;
- }
- for (int i = 0; i < m.length; i++) {
- for (int j = i + 1; j < m.length; j++) {
- if(m[i][j] == 0) {
- int posx = i+1;
- while(m[i][posx] != 0) {
- m[i][j] = m[posx][j];
- m[j][i] = m[posx][j];
- }
- }
- }
- }
- for (int i = 0; i < m.length; i++) {
- for (int j = 0; j < m.length; j++) {
- System.out.print(m[i][j] + " ");
- }
- System.out.println();
- }
- }
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement