import java.util.*;
class BFS extends Graph {
Queue<Integer> s = new LinkedList<Integer>();

int BFSTree(int root) {
 int Search = new int [nodes.size()];
 int tree = new int [nodes.size()];
 s.offer(root);
 for (int i = 0; i < nodes.size(); i++) {
 Search[i] = 1;
 }
while (s.peek() != null) {
 int x = s.poll();
 Search[root] = -1;
 for (int k = 0; k < nodes.get(x).getNum(); k++) {
 if (Search[list.get(nodes.get(x).getPointer() + k).To()] == 1 ){
 s.offer(list.get(nodes.get(x).getPointer() + k).To());
 Search[list.get(nodes.get(x).getPointer() + k).To()] = -1 ;
 tree[list.get(nodes.get(x).getPointer() + k).To()] = x;}
   }
  }
 return tree;
 }
}
class BFSTester {
public static void main (String args){
 int[] Tree;
 BFS b = new BFS();
 b.LoadGraph("graph001.txt");
 Tree = b.BFSTree(0);
 System.out.print(Tree[0]);
 for (int m = 1; m < Tree.length; m++)
 System.out.print("," + Tree[m]);
  }
 }