Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void death(long x, long y, long n, long c, long mas[], long h, byte a[][]){
- long opa[] = new long[20001];
- y=x;
- for (int i = 1; i < n; i++){
- opa[i] = 0;
- }
- c = 0;
- h = 0;
- ++c;
- opa[(int)c] = x;
- while (h < c){
- ++h;
- x = opa[(int)h];
- for (int i = 0; i < n; i++){
- if (a[(int)x][i]!= 0 && (mas[i]==0) && (i !=y)){
- ++c;
- opa[(int)c]=i;
- mas[i] = mas[(int)x]+1;
- }
- }
- }
- }
- public static void main(String[] args) {
- long mas[] = new long[20001];
- Scanner sc = new Scanner(System.in);
- byte a[][] = new byte[20001][20001];
- long c=0, h=0, n, k, y = 0, s, m, x1, x2, j, max=0;
- n = sc.nextLong();
- m = sc.nextLong();
- s = sc.nextLong();
- for (int i = 0; i < m; i++){
- x1 = sc.nextLong();
- x2 = sc.nextLong();
- a[(int)x2][(int)x1] = 1;
- }
- death(s,y,n,c, mas, h, a);
- max=0;
- for(int i = 0; i < n; i++){
- if (mas[i]> max){
- max = mas[i];
- }
- }
- System.out.println(max);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement