daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) throws FileNotFoundException {
  7.  
  8.         FileReader read = new FileReader("in.txt");
  9.         Scanner reader = new Scanner(read);
  10.         int n = reader.nextInt();
  11.         int[][] graf = new int[n][n];
  12.         for (int i = 0; i < n; i++) {
  13.             for (int j = 0; j < n; j++) {
  14.                 graf[i][j] = reader.nextInt();
  15.             }
  16.         }
  17.  
  18.  
  19.         int wyniki[] = new int[n];
  20.         int kolory[] = new int[n - 1];
  21.         for (int i = 0; i < kolory.length; i++) {
  22.             kolory[i] = i;
  23.             wyniki[i] = -1;
  24.         }
  25.         wyniki[0] = 0;
  26.         int tmp = 100;
  27.         for (int i = 1; i < n; i++) {
  28.             for (int j = 0; j < i; j++) {
  29.                 if (graf[i][j] == 0) {
  30.  
  31.                     wyniki[i] = wyniki[j];
  32.                     break;
  33.                 }
  34.                 if (graf[i][j] == 1) {
  35.                     if (wyniki[j] < tmp) {
  36.                         tmp = wyniki[j];
  37.  
  38.                     }
  39.                     wyniki[i] = ++tmp;
  40.                 }
  41.             }
  42.  
  43.  
  44.         }
  45.  
  46.  
  47.         for (int i = 0; i < n; i++)
  48.             System.out.print(wyniki[i] + " ");
  49.     }
  50.  
  51.  
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top