Language: Java

public class Main {

    @SuppressWarnings("unchecked")
    static void solve() throws Exception {
        int N = scanInt(), M = scanInt();
        int[][] load = new int[N][N];
        int[] index = new int[N];
        int[] ans = new int[N];
        ans[0] = 1;
        int count = 0;
        for (int i = 0; i < M; i++) {
            int A = scanInt();
            int B = scanInt();
            load[A-1][index[A-1]] = B;
            load[B-1][index[B-1]] = A;
            index[A-1]++;
            index[B-1]++;
        }
//        for (int i = 0; i < N; i++) {
//            for (int j = 0; j < N; j++) {
//              System.out.print(load[i][j]);
//
//            }
//            System.out.println("");
//        }
        ArrayList<Integer> next = new ArrayList<Integer>();
        next.add(1);
        for (int F = 1; F < N; F++) {
            ArrayList<Integer> tn = (ArrayList<Integer>) next.clone();
            next = new ArrayList<>();
            for (int nk : tn) {
                for (int j = 0; j < index[nk-1]; j++) {
                    int tmp = load[nk-1][j];
                    if (ans[tmp-1] == 0) {
                        ans[tmp-1] = nk;
                        next.add(tmp);
                        count++;
                    }
                    if (count == N - 1) {
                        break;
                    }
                }
                if (count == N - 1) {
                    break;
                }
            }
            if (count == N - 1) {
                break;
            }
        }

        if (count == N - 1) {
            System.out.println("Yes");
            for (int i = 1; i < N; i++) {
                System.out.println(ans[i]);
            }
        } else {
            System.out.println("No");
        }

    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

Compiler output:
Main.java:63: error: cannot find symbol
    static int scanInt() throws IOException {
                                ^
  symbol:   class IOException
  location: class Main
Main.java:67: error: cannot find symbol
    static long scanLong() throws IOException {
                                  ^
  symbol:   class IOException
  location: class Main
Main.java:71: error: cannot find symbol
    static String scanString() throws IOException {
                                      ^
  symbol:   class IOException
  location: class Main
Main.java:78: error: cannot find symbol
    static BufferedReader in;
           ^
  symbol:   class BufferedReader
  location: class Main
Main.java:79: error: cannot find symbol
    static PrintWriter out;
           ^
  symbol:   class PrintWriter
  location: class Main
Main.java:80: error: cannot find symbol
    static StringTokenizer tok;
           ^
  symbol:   class StringTokenizer
  location: class Main
Main.java:26: error: cannot find symbol
        ArrayList<Integer> next = new ArrayList<Integer>();
        ^
  symbol:   class ArrayList
  location: class Main
Main.java:26: error: cannot find symbol
        ArrayList<Integer> next = new ArrayList<Integer>();
                                      ^
  symbol:   class ArrayList
  location: class Main
Main.java:29: error: cannot find symbol
            ArrayList<Integer> tn = (ArrayList<Integer>) next.clone();
            ^
  symbol:   class ArrayList
  location: class Main
Main.java:29: error: cannot find symbol
            ArrayList<Integer> tn = (ArrayList<Integer>) next.clone();
                                     ^
  symbol:   class ArrayList
  location: class Main
Main.java:30: error: cannot find symbol
            next = new ArrayList<>();
                       ^
  symbol:   class ArrayList
  location: class Main
Main.java:64: error: cannot find symbol
        return parseInt(scanString());
               ^
  symbol:   method parseInt(String)
  location: class Main
Main.java:68: error: cannot find symbol
        return parseLong(scanString());
               ^
  symbol:   method parseLong(String)
  location: class Main
Main.java:73: error: cannot find symbol
            tok = new StringTokenizer(in.readLine());
                      ^
  symbol:   class StringTokenizer
  location: class Main
Main.java:84: error: cannot find symbol
            in = new BufferedReader(new InputStreamReader(System.in));
                     ^
  symbol:   class BufferedReader
  location: class Main
Main.java:84: error: cannot find symbol
            in = new BufferedReader(new InputStreamReader(System.in));
                                        ^
  symbol:   class InputStreamReader
  location: class Main
Main.java:85: error: cannot find symbol
            out = new PrintWriter(System.out);
                      ^
  symbol:   class PrintWriter
  location: class Main
Main.java:92: error: cannot find symbol
            exit(1);
            ^
  symbol:   method exit(int)
  location: class Main
18 errors