Advertisement
Guest User

B4 in LOSH 2016

a guest
Jul 30th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void death(long x, long y, long n, long c, long mas[], long h, byte a[][]){
  5.         long opa[] = new long[20001];
  6.         y=x;
  7.         for (int i = 1; i < n; i++){
  8.             opa[i] = 0;
  9.         }
  10.         c = 0;
  11.         h = 0;
  12.         ++c;
  13.         opa[(int)c] = x;
  14.         while (h < c){
  15.             ++h;
  16.             x = opa[(int)h];
  17.             for (int i = 0; i < n; i++){
  18.                 if (a[(int)x][i]!= 0 && (mas[i]==0) && (i !=y)){
  19.                     ++c;
  20.                     opa[(int)c]=i;
  21.                     mas[i] = mas[(int)x]+1;
  22.                 }
  23.             }
  24.         }
  25.     }
  26.     public static void main(String[] args) {
  27.         long mas[] = new long[20001];
  28.         Scanner sc = new Scanner(System.in);
  29.         byte a[][] = new byte[20001][20001];
  30.         long c=0, h=0, n, k, y = 0, s, m, x1, x2, j, max=0;
  31.         n = sc.nextLong();
  32.         m = sc.nextLong();
  33.         s = sc.nextLong();
  34.         for (int i = 0; i < m; i++){
  35.             x1 = sc.nextLong();
  36.             x2 = sc.nextLong();
  37.             a[(int)x2][(int)x1] = 1;
  38.         }
  39.         death(s,y,n,c, mas, h, a);
  40.         max=0;
  41.         for(int i = 0; i < n; i++){
  42.             if (mas[i]> max){
  43.                 max = mas[i];
  44.             }
  45.         }
  46.         System.out.println(max);
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement