/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package security; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.StringTokenizer; import javafx.util.Pair; /** * * @author cteam063 */ public class Security { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { // TODO code application logic here BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer row1 = new StringTokenizer(in.readLine()); int numg = Integer.parseInt(row1.nextToken()); int numi = Integer.parseInt(row1.nextToken()); int[] guardsX = new int[numg]; int[] guardsY = new int[numg]; int[] inciX = new int[numi]; int[] inciY = new int[numi]; int[][] world = new int[5001][5001]; for (int i = 0; i> q = new ArrayDeque<>(); for (int j=0; j(guardsX[j],guardsY[j])); world[guardsX[j]][guardsY[j]] = 0; } Pair tmp; while(!q.isEmpty()){ tmp = q.poll(); //System.out.println(tmp.getKey() + " " + tmp.getValue()); if (test(tmp.getKey()+1, tmp.getValue(), world)) { q.add(new Pair(tmp.getKey()+1, tmp.getValue())); world[tmp.getKey()+1][tmp.getValue()]= world[tmp.getKey()][tmp.getValue()] + 1; } if (test(tmp.getKey()-1, tmp.getValue(), world)) { q.add(new Pair(tmp.getKey()-1, tmp.getValue())); world[tmp.getKey()-1][tmp.getValue()]= world[tmp.getKey()][tmp.getValue()] + 1; } if (test(tmp.getKey(), tmp.getValue()+1, world)) { q.add(new Pair(tmp.getKey(), tmp.getValue()+1)); world[tmp.getKey()][tmp.getValue()+1]= world[tmp.getKey()][tmp.getValue()] + 1; } if (test(tmp.getKey()+1, tmp.getValue()-1, world)) { q.add(new Pair(tmp.getKey()+1, tmp.getValue()-1)); world[tmp.getKey()+1][tmp.getValue()-1]= world[tmp.getKey()][tmp.getValue()] + 1; } if (test(tmp.getKey()+1, tmp.getValue()+1, world)) { q.add(new Pair(tmp.getKey()+1, tmp.getValue()+1)); world[tmp.getKey()+1][tmp.getValue()+1]= world[tmp.getKey()][tmp.getValue()] + 1; } if (test(tmp.getKey()+1, tmp.getValue()-1, world)) { q.add(new Pair(tmp.getKey()+1, tmp.getValue()-1)); world[tmp.getKey()+1][tmp.getValue()-1]= world[tmp.getKey()][tmp.getValue()] + 1; } if (test(tmp.getKey()-1, tmp.getValue()+1, world)) { q.add(new Pair(tmp.getKey()-1, tmp.getValue()+1)); world[tmp.getKey()-1][tmp.getValue()+1]= world[tmp.getKey()][tmp.getValue()] + 1; } if (test(tmp.getKey()-1, tmp.getValue()-1, world)) { q.add(new Pair(tmp.getKey()-1, tmp.getValue()-1)); world[tmp.getKey()-1][tmp.getValue()-1]= world[tmp.getKey()][tmp.getValue()] + 1; } } for (int i =0; i a = new Pair<>(1,2); //for (int i =0; i 5000) || (y < 0) || (y > 5000) || (v[x][y] != -1)) return false; else return true; } }