diff --git a/ADK-labb3-Testing/BipRed.java b/ADK-labb3-Testing/BipRed.java new file mode 100644 index 0000000..dd3847e --- /dev/null +++ b/ADK-labb3-Testing/BipRed.java @@ -0,0 +1,141 @@ +import java.util.*; + +/** + * Programmet löser matchningsproblemet med hjälp av en svart låda som löser flödesproblemet. + * + * @author Emilia Rieschel & Charlotta Johnsson + * @date 2021-11-03 + */ + + +public class BipRed { + private Kattio io; + private int vertices; + private int xNodes; + private int yNodes; + private int maxFlow; + private int sink; + private int source; + private LinkedList[]edges; + private int numberOfEdges; + private LinkedList result; + + void readBipartiteGraph() { + + // Läs antal hörn och kanter + int x = io.getInt(); + int y = io.getInt(); + int e = io.getInt(); + + // Spara globala variabler + numberOfEdges = e + x + y; + vertices = x + y + 2; //För vi lägger till s och t + edges = new LinkedList[x+y+2]; //en array av LinkedList med plats för alla noder förutom sink + xNodes = x; + yNodes = y; + source = 1; + sink = vertices; + + // Skapar en LinkedList för varje nod, där kommer kanter till noden att vara + for(int i = 1; i < edges.length; i++){ + edges[i] = new LinkedList(); + } + + // Skapar en kant mellan source och alla X-noder + for(int i = 1; i <= x; i++){ + edges[1].add(new Edge((i+1),1,0,0)); + } + + // Skapar en kant mellan alla Y-noder och sink + for(int i = x+1; i < vertices-1; i++){ + edges[i+1].add(new Edge(vertices, 1, 0, 0)); + } + + // Läs in kanterna och skapa en Edge för kanten + for (int i = 0; i < e; ++i) { + int a = io.getInt(); + int b = io.getInt(); + edges[a+1].add(new Edge((b+1), 1, 0, 0)); + } + } + + + void writeFlowGraph() { + + // Skriv ut antal hörn och kanter samt källa och sänka + io.println(vertices); + io.println((source) + " " + (sink)); + io.println(numberOfEdges); + + // Skriv ut alla kanter och dess kapacitet + for (int i = 1; i < edges.length; i++){ + for(Edge e: edges[i]){ + io.println(i + " " + e.getY() + " " + e.getCapacity()); + } + } + + io.flush(); + } + + + void readMaxFlowSolution() { + + // Läs in antal hörn, kanter, källa, sänka, och totalt flöde + int v = io.getInt(); + int s = io.getInt(); + int t = io.getInt(); + int totalflow = io.getInt(); + int e = io.getInt(); + + // Spara global variabel + maxFlow = totalflow; + + // Skapa lista för resultatet + result = new LinkedList<>(); + + // Läs in alla kanter och flödet + for (int i = 0; i < e; ++i) { + int a = io.getInt(); + int b = io.getInt(); + int f = io.getInt(); + + // Om kanten inte är från source eller till sink och flöder är 1, lägg till i resultatlistan + if(f == 1 && a != source && b != sink){ + result.add(new SimpleEdge((a-1),(b-1))); + } + } + } + + + void writeBipMatchSolution() { + + // Skriv ut antal hörn och storleken på matchningen + io.println(xNodes + " " + yNodes); + io.println(maxFlow); + + // Skriv ut kanterna i matchningen + for(SimpleEdge e: result){ + io.println(e.getFrom() + " " + e.getTo()); + } + } + + + BipRed() { + + io = new Kattio(System.in, System.out); + + readBipartiteGraph(); + + writeFlowGraph(); + + readMaxFlowSolution(); + + writeBipMatchSolution(); + + io.close(); + } + + public static void main(String args[]) { + new BipRed(); + } +} diff --git a/ADK-labb3-Testing/Edge.class b/ADK-labb3-Testing/Edge.class new file mode 100644 index 0000000..1a81d84 Binary files /dev/null and b/ADK-labb3-Testing/Edge.class differ diff --git a/ADK-labb3-Testing/Edge.java b/ADK-labb3-Testing/Edge.java new file mode 100644 index 0000000..b81ab7d --- /dev/null +++ b/ADK-labb3-Testing/Edge.java @@ -0,0 +1,51 @@ +/** + * @author Emilia Rieschel & Charlotta Johnsson + * @date 2021-11-03 + */ + + +public class Edge { + private int capacity; + private int flow; + private int y; + private int res; + + Edge(int y, int c, int flow, int res){ + this.y = y; + this.capacity = c; + this.flow = flow; + this.res = res; + } + + public int getY(){ + return y; + } + + public int getCapacity() { + return capacity; + } + + public int getFlow() { + return flow; + } + + public int getRes(){ + return res; + } + + public void setCapacity(int c) { + capacity = c; + } + + public void changeRes(int f) { + res = capacity + f; + } + + public void setFlow(int f) { + flow = f; + } + + public void increaseFlow(int f) { + flow += f; + } +} diff --git a/ADK-labb3-Testing/Kattio.class b/ADK-labb3-Testing/Kattio.class new file mode 100644 index 0000000..909180c Binary files /dev/null and b/ADK-labb3-Testing/Kattio.class differ diff --git a/ADK-labb3-Testing/Kattio.java b/ADK-labb3-Testing/Kattio.java new file mode 100644 index 0000000..45a9bee --- /dev/null +++ b/ADK-labb3-Testing/Kattio.java @@ -0,0 +1,66 @@ +import java.util.StringTokenizer; +import java.io.BufferedReader; +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.OutputStream; + +public class Kattio extends PrintWriter { + public Kattio(InputStream i) { + super(new BufferedOutputStream(System.out)); + r = new BufferedReader(new InputStreamReader(i)); + } + public Kattio(InputStream i, OutputStream o) { + super(new BufferedOutputStream(o)); + r = new BufferedReader(new InputStreamReader(i)); + } + + public boolean hasMoreTokens() { + return peekToken() != null; + } + + public int getInt() { + return Integer.parseInt(nextToken()); + } + + public double getDouble() { + return Double.parseDouble(nextToken()); + } + + public long getLong() { + return Long.parseLong(nextToken()); + } + + public String getWord() { + return nextToken(); + } + + + + private BufferedReader r; + private String line; + private StringTokenizer st; + private String token; + + private String peekToken() { + if (token == null) + try { + while (st == null || !st.hasMoreTokens()) { + line = r.readLine(); + if (line == null) return null; + st = new StringTokenizer(line); + } + token = st.nextToken(); + } catch (IOException e) { } + return token; + } + + private String nextToken() { + String ans = peekToken(); + token = null; + return ans; + } +} + diff --git a/ADK-labb3-Testing/Matchreduce.java b/ADK-labb3-Testing/Matchreduce.java new file mode 100644 index 0000000..cd99f99 --- /dev/null +++ b/ADK-labb3-Testing/Matchreduce.java @@ -0,0 +1,182 @@ +import java.util.*; + +/** + * Löser matchningsproblemet för bipartita grafer. + * + * @author Emilia Rieschel & Charlotta Johnsson + * @date 2021-11-03 + */ + +public class MatchReduce { + private Kattio io; + private int vertices; + private int xNodes; + private int yNodes; + private int maxFlow; + private int sink; + private int source; + private LinkedList[]edges; + private int numberOfEdges; + private Queue queue; + private int[] parent; + + void readBipartiteGraph() { + + // Läser in antal hörn och kanter + int x = io.getInt(); + int y = io.getInt(); + int e = io.getInt(); + + numberOfEdges = e + x + y; + vertices = x + y + 2; + edges = new LinkedList[vertices+1]; + xNodes = x; + yNodes = y; + source = 1; + sink = vertices; + + //Initialisera linkedlist för alla index i edges + for(int i = 1; i < edges.length; i++){ + edges[i] = new LinkedList(); + } + + //Lägg till kanter från source till alla X-noder + for(int i = 1; i <= x; i++){ + edges[1].add(new Edge((i+1),1,0,1)); + } + + //Lägg till kanter från alla Y-noder till sink + for(int i = x+1; i < vertices-1; i++){ + edges[i+1].add(new Edge(vertices, 1, 0, 1)); + } + + // Läs in kanterna + for (int i = 0; i < e; ++i) { + int a = io.getInt(); + int b = io.getInt(); + edges[a+1].add(new Edge((b+1), 1, 0, 1)); + } + } + + + public int findIndex(int from, int to){ + int index = 0; + for(Edge e: edges[from]){ + if(e.getY() == to){ + return index; + } + index++; + } + edges[from].add(new Edge(to, 0, 0, 0)); + return edges[from].size()-1; + } + + + public boolean bfs(int[] parent){ + + boolean[] visited = new boolean[vertices+1]; + for (int i = 0; i < vertices + 1; ++i) + visited[i] = false; + + queue.add(source); + visited[source] = true; + parent[source] = -1; + + while (queue.size() != 0) { + int u = queue.poll(); + + for(Edge e: edges[u]){ + int v = e.getY(); + if(visited[v] == false && e.getRes() > 0){ + if (v == sink) { + parent[v] = u; + return true; + } + queue.add(v); + parent[v] = u; + visited[v] = true; + } + } + } + + return false; + } + + + public int fordFulkerson(){ + + queue = new LinkedList(); + parent = new int[vertices+1]; + int maxFlow = 0; + + while (bfs(parent)) { + + int pathFlow = Integer.MAX_VALUE; + int v = sink; + int u; + int indexOfElement; + LinkedList indexList = new LinkedList<>(); + + while(v != source){ + u = parent[v]; + indexOfElement = findIndex(u, v); + pathFlow = Math.min(pathFlow, edges[u].get(indexOfElement).getRes()); + v = u; + indexList.add(indexOfElement); + } + + v = sink; + int tempflow = 0; + int indexOfElementU; + + while (v != source) { + indexOfElement = indexList.poll(); + u = parent[v]; + indexOfElementU = findIndex(v, u); + edges[u].get(indexOfElement).increaseFlow(pathFlow); + tempflow = edges[u].get(indexOfElement).getFlow(); + edges[v].get(indexOfElementU).setFlow(-tempflow); + edges[u].get(indexOfElement).changeRes(-tempflow); + edges[v].get(indexOfElementU).changeRes(tempflow); + v = u; + } + + maxFlow += pathFlow; + + queue.clear(); + } + return maxFlow; + + } + + MatchReduce() { + + io = new Kattio(System.in, System.out); + + readBipartiteGraph(); + + int maxflow = fordFulkerson(); + + // Skriv ut antal hörn i X och i Y + io.println(xNodes + " " + yNodes); + + // Skriv ut antalet kanter funna i matchningen (samma som maxflödet i en bipartit graf) + io.println(maxflow); + + // Skriv ut alla kanter som ingår i matchningen + // Gå bara igenom kanterna från en X-nod till en Y-nod + for(int i = 2; i < edges.length-1-yNodes; i++){ + for(Edge e: edges[i]){ + if(e.getFlow() == 1){ + io.println((i-1) + " " + (e.getY()-1)); + } + } + } + + io.close(); + } + + public static void main(String args[]) { + new MatchReduce(); + } +} diff --git a/ADK-labb3-Testing/SimpleEdge.class b/ADK-labb3-Testing/SimpleEdge.class new file mode 100644 index 0000000..f51f8fe Binary files /dev/null and b/ADK-labb3-Testing/SimpleEdge.class differ diff --git a/ADK-labb3-Testing/SimpleEdge.java b/ADK-labb3-Testing/SimpleEdge.java new file mode 100644 index 0000000..48baca4 --- /dev/null +++ b/ADK-labb3-Testing/SimpleEdge.java @@ -0,0 +1,23 @@ +/** + * @author Emilia Rieschel & Charlotta Johnsson + * @date 2021-11-03 + */ + + +public class SimpleEdge { + private int from; + private int to; + + SimpleEdge(int from, int to){ + this.from = from; + this.to = to; + } + + public int getFrom() { + return from; + } + + public int getTo() { + return to; + } +} \ No newline at end of file diff --git a/ADK-labb3-Testing/SolveFP.java b/ADK-labb3-Testing/SolveFP.java new file mode 100644 index 0000000..f6df660 --- /dev/null +++ b/ADK-labb3-Testing/SolveFP.java @@ -0,0 +1,213 @@ +import java.util.LinkedList; +import java.util.Queue; + +/** + * Programmet löser flödesproblemet. + * + * @author Emilia Rieschel & Charlotta Johnsson + * @date 2021-11-03 + */ + + +public class SolveFP{ + private Kattio io; + private int sink; + private int source; + private int a; + private int b; + private int c; + private int e; + private int vertices; + private int[] parent; + private LinkedList[]edges; + private Queue queue; + + + SolveFP() { + io = new Kattio(System.in, System.out); + + // Läser in antalet noder och kanter samt source och sink. + vertices = io.getInt(); + source = io.getInt(); + sink = io.getInt(); + e = io.getInt(); + + // Skapar arrayen med alla LinkedList som kommer att innehålla alla kanter + edges = new LinkedList[vertices+1]; + for(int i = 1; i < edges.length; i++){ + edges[i] = new LinkedList(); + } + + // Läser in alla kanter och dess kapacitet, samt skapar en Edge för den kanten + for(int i = 0; i < e; i++){ + a = io.getInt(); + b = io.getInt(); + c = io.getInt(); + edges[a].add(new Edge(b, c, 0, c)); + } + + // Räknar ut det maximala flödet för den givna grafen + int flow = fordFulkerson(); + + // Skriver ut antalet kanter, source, sink, samt totala flödet från source till sink + io.println(vertices); + io.println(source + " " + sink + " " + flow); + + // Räknar och skriver ut hur många kanter som ingår i flödet + int count = 0; + for(int i = 1; i < edges.length; i++){ + for(Edge e: edges[i]){ + if(e.getFlow() > 0){ + count++; + } + } + } + io.println(count); + + // Skriver ut alla kanter som ingår i maximala flödet, samt kanternas flöde + for(int i = 1; i < edges.length; i++){ + for(Edge e: edges[i]){ + if(e.getFlow() > 0){ + io.println(i + " " + e.getY() + " " + e.getFlow()); + } + } + } + + io.flush(); + io.close(); + } + + + /** + * Metod för att hitta vilket index i edges[from] som har y-värdet to. Om det inte tidigare finns någon kant + * mellan from och to, så skapas en ny kant mellan dem. + * @param from Noden som kanten går från. + * @param to Noden som kanten går till. + * @return Indexet för kanten i edges[from] + */ + public int findIndex(int from, int to){ + int index = 0; + + // Gå igenom alla kanter tills man kommer till rätt, och returnera då indexet. + for(Edge e: edges[from]){ + if(e.getY() == to){ + return index; + } + index++; + } + + // Om kanten inte fanns, skapa en ny kant och returnera indexet för den kanten. + edges[from].add(new Edge(to, 0, 0, 0)); + return edges[from].size()-1; + } + + /** + * Hittar den kortaste vägen med breddenförstsökning, och sparar den hittade vägen i parent. + * @param parent Här kommer den hittade vägen att komma. + * @return True om det hittas en väg, falskt annars. + */ + public boolean bfs(int[] parent){ + + // Skapa en array visited för att hålla koll på vilka noder man redan har besökt. + boolean[] visited = new boolean[vertices+1]; + for (int i = 0; i < vertices + 1; ++i) + visited[i] = false; + + // Lägg till första noden, det vill säga source, till kön. + queue.add(source); + visited[source] = true; + parent[source] = -1; // Vi var inte på någon annan nod innan. + + // Breddenförstsökning, forsätt med loopen tills det inte finns något element kvar i kön. + while (queue.size() != 0) { + int u = queue.poll(); + + // Gå igenom varje kant, det vill säga varje granne till u + for(Edge e: edges[u]){ + int v = e.getY(); + + // Om vi inte tidigare har varit på noden och residualgrafens flöde är större än 0, lägg till noden i kön. + if(visited[v] == false && e.getRes() > 0){ + + // Om vi har kommit till sink, har vi hittat en stig och vi är färdiga. + if (v == sink) { + parent[v] = u; + return true; + } + + // Annars lägger vi till noden i kön och fortsätter. + queue.add(v); + parent[v] = u; + visited[v] = true; + } + } + } + + // Det fanns ingen väg från source till sink, och det returneras därför false. + return false; + } + + + public int fordFulkerson(){ + + // Vi skapar kön som kommer att användes i breddenförstsökningen. + queue = new LinkedList(); + + // parent kommer att spara vägen som hittas i breddenförstsökningen + parent = new int[vertices+1]; + + // flödet är 0 från början + int maxFlow = 0; + + while (bfs(parent)) { + + int pathFlow = Integer.MAX_VALUE; + int v = sink; + int u; + + // För att vi inte ska behöva räkna ut samma index flera gånger. + int indexOfElement; + LinkedList indexList = new LinkedList<>(); + + // Hitta högsta möjliga flödet genom vägen given av parent. + while(v != source){ + u = parent[v]; + indexOfElement = findIndex(u, v); + pathFlow = Math.min(pathFlow, edges[u].get(indexOfElement).getRes()); + v = u; + indexList.add(indexOfElement); + } + + v = sink; + int tempflow; + int indexOfElementU; + + // Ändra flödet och residualgrafen enligt givna algoritmen för Ford-Fulkerson + while (v != source) { + indexOfElement = indexList.poll(); + u = parent[v]; + indexOfElementU = findIndex(v, u); + + edges[u].get(indexOfElement).increaseFlow(pathFlow); + tempflow = edges[u].get(indexOfElement).getFlow(); + edges[v].get(indexOfElementU).setFlow(-tempflow); + edges[u].get(indexOfElement).changeRes(-tempflow); + edges[v].get(indexOfElementU).changeRes(tempflow); + v = u; + } + + // Lägg till flödet på totala flödet + maxFlow += pathFlow; + + // Rensa kön som används i breddenförstsökningen + queue.clear(); + } + + // Returnera det totala flödet + return maxFlow; + } + + public static void main(String args[]) { + new SolveFP(); + } +} diff --git a/ADK-labb3-Testing/test.indata b/ADK-labb3-Testing/test.indata new file mode 100644 index 0000000..6c4ec8e --- /dev/null +++ b/ADK-labb3-Testing/test.indata @@ -0,0 +1,15 @@ +2 3 +4 +1 3 +1 4 +2 3 +2 5 +7 +1 7 2 +6 +1 2 1 +1 3 1 +2 4 1 +3 6 1 +4 7 1 +6 7 1 \ No newline at end of file diff --git a/ADK-labb3-Testing/test.utdata b/ADK-labb3-Testing/test.utdata new file mode 100644 index 0000000..a042b58 --- /dev/null +++ b/ADK-labb3-Testing/test.utdata @@ -0,0 +1,5 @@ +1 2 1 +1 3 2 +2 4 2 +3 2 1 +3 4 1 diff --git a/C$pair.class b/C$pair.class new file mode 100644 index 0000000..8b8a27c Binary files /dev/null and b/C$pair.class differ diff --git a/C.class b/C.class new file mode 100644 index 0000000..879c7cf Binary files /dev/null and b/C.class differ diff --git a/C.java b/C.java new file mode 100644 index 0000000..7eda2bf --- /dev/null +++ b/C.java @@ -0,0 +1,217 @@ +import java.util.*; + +public class C { + private int verticalMoves; + private int horizontalMoves; + private int size; + boolean[][] visited; + char chessboard[][]; + + static class pair{ + int first, second; + + public pair(int first, int second) + { + this.first = first; + this.second = second; + } + } + + public C(int verticalMoves, int horizontalMoves, int size) { + this.verticalMoves = verticalMoves; + this.horizontalMoves = horizontalMoves; + this.size = size; + this.visited = new boolean[size][size]; + this.chessboard = new char[size][size]; + } + + public boolean isLegalMove(int positionX, int positionY) { + return (positionX < size && positionY < size && positionX >= 0 && positionY >= 0); + + } + + public void colorPath(int startColor, Stack path){ + int colorindex = startColor; + while (!path.empty()){ + pair curr = path.pop(); + int row = curr.first; + int col = curr.second; + //System.out.println("row " + row + " col " + col); + + if (colorindex % 2 == 0){ + chessboard[row][col] = 'X'; + //System.out.println("X"); + + } + else{ + chessboard[row][col] = 'O'; + //System.out.println("O"); + } + colorindex++; + } + /* for ( int i = 0; i st = new Stack(); + Stack path = new Stack(); + st.push(new pair(row, col)); + + //visited[row][col] = true; + + + while (!st.empty()) { + // Pop the top pair + pair curr = st.pop(); + + row = curr.first; + col = curr.second; + + if (visited[row][col] == true){ + continue; + } + + visited[row][col] = true; + path.push(curr); + + int[][] moves = possibleMoves(row, col); + + //if no legal moves we have reached an end point, + boolean reachedEnd = true; + + //System.out.println("pushing " + row + " " + col + "\n"); + System.out.println("current square " + row + " "+ col); + for (int i = 0; i (); + reachedEnd = false; + } + else if (chessboard[moves[i][0]][moves[i][1]] == '0'){ + if (chessboard[row][col] == '0'){ + //System.out.println("Ahaaaaaa O"); + //return false; + } + colorPath(0, path); + path = new Stack(); + reachedEnd = false; + } + } + + } + } + if (reachedEnd){ //if no legal moves we have reached an end point, + System.out.println("reached end"); + colorPath(0, path); + path = new Stack(); + } + } + return true; + } + + + + public int[][] possibleMoves(int positionX, int positionY) { + int possibleMoves[][] = new int[8][2]; + possibleMoves[0][0] = positionX + verticalMoves; + possibleMoves[0][1] = positionY + horizontalMoves; + + possibleMoves[1][0] = positionX + verticalMoves; + possibleMoves[1][1] = positionY - horizontalMoves; + + possibleMoves[2][0] = positionX - verticalMoves; + possibleMoves[2][1] = positionY + horizontalMoves; + + possibleMoves[3][0] = positionX - verticalMoves; + possibleMoves[3][1] = positionY - horizontalMoves; + + possibleMoves[4][0] = positionX + horizontalMoves; + possibleMoves[4][1] = positionY + verticalMoves; + + possibleMoves[5][0] = positionX + horizontalMoves; + possibleMoves[5][1] = positionY - verticalMoves; + + possibleMoves[6][0] = positionX - horizontalMoves; + possibleMoves[6][1] = positionY + verticalMoves; + + possibleMoves[7][0] = positionX - horizontalMoves; + possibleMoves[7][1] = positionY - verticalMoves; + + return possibleMoves; + + } + + public char[][] createChessboard(){ + + for (int i=0; i= 0 && positionY >= 0); + + } + + public void colorPath(int startColor, Stack path){ + int colorindex = startColor; + while (!path.empty()){ + pair curr = path.pop(); + int row = curr.first; + int col = curr.second; + //System.out.println("row " + row + " col " + col); + + if (colorindex % 2 == 0){ + chessboard[row][col] = 'X'; + //System.out.println("X"); + + } + else{ + chessboard[row][col] = 'O'; + //System.out.println("O"); + } + colorindex++; + } + /* for ( int i = 0; i st = new Stack(); + Stack path = new Stack(); + st.push(new pair(row, col)); + + + while (!st.empty()) { + // Pop the top pair + pair curr = st.pop(); + + row = curr.first; + col = curr.second; + + int[][] moves = possibleMoves(row, col); + + /* //print possible moves + System.out.println("current square " + row + " "+ col); + for (int i = 0; i (); + reachedEnd = false; + } + else if (chessboard[moves[i][0]][moves[i][1]] == '0'){ + if (chessboard[row][col] == '0'){ + System.out.println("Ahaaaaaa O"); + //return false; + } + /* if (path.empty()){ + System.out.println("0: " + chessboard[row][col]); + if (chessboard[row][col] == '0'){ + System.out.println("error"); + return false; + } + } */ + colorPath(0, path); + path = new Stack(); + reachedEnd = false; + + } + } + if (reachedEnd){ //if no legal moves we have reached an end point, + //System.out.println("reached end"); + colorPath(0, path); + //print stack + path = new Stack(); + } + } + } + } + } + return true; + } + + /* public void BFS(int row, int col){ + + // Stores indices of the matrix cells + Queue q = new LinkedList<>(); + + q.add(new move(row, col)); + //System.out.println("The first move is: " + row + " " + col); + //System.out.println("visited length " + visited.length); + visited[row][col] = true; + chessboard[row][col] = 'X'; + + // Iterate while the queue + // is not empty + while (!q.isEmpty()) + { + move square = q.peek(); + int x = square.first; + int y = square.second; + + q.remove(); + + int[][] moves = possibleMoves(x, y); + + for (int i = 0; i = 0 && possibleMoves[k][0] < size && possibleMoves[k][1] >= 0 && possibleMoves[k][1] < size){ + if (chessboard[possibleMoves[k][0]][possibleMoves[k][1]] == chessboard[i][j]){ + System.out.println("x = " + i + " y = " + j ); + System.out.println(); + printChess(chessboard); + return false; + } + } + } + + } + } + return true; + + } + + + public static void main(String[] args) { + Test test = new Test(); + + int n = 8; + for (int i = 2; i <= n; i++) { + for (int j=1; j new_distance: + visited_and_distance[neighbor_index][1] = new_distance + + visited_and_distance[to_visit][0] = 1 + +i = 0 + +# Printing the distance +for distance in visited_and_distance: + print("Distance of ", chr(ord('a') + i), + " from source vertex: ", distance[1]) + i = i + 1 \ No newline at end of file