Language: Java

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
long long n,m;
struct Passages{
    long long x,y;
};
Passages p[200050];
long long ans[200050];
bool b[100500];
int main()
{
    cin>>n>>m;
    queue<long long>q;
    for(int i=2;i<=n;i++)
        b[i] = true;
    int count=1;
    for(int i=0;i<m;i++) {
        scanf("%lld%lld", &p[i].x, &p[i].y);
        if(p[i].x==1) {
            q.push(p[i].y);
            ans[p[i].y]=1;
            b[p[i].y]=false;
            //<<p[i].y<<"  "<<ans[p[i].y]<<endl;
            count++;
        }
        if(p[i].y==1) {
            q.push(p[i].x);
            ans[p[i].x]=1;
            b[p[i].x]=false;
            //cout<<p[i].x<<"  "<<ans[p[i].x]<<endl;
            count++;
        }
    }
    //cout<<count<<endl;
    if(q.empty())
        cout<<"-1";
    else{
        while(!q.empty()){
            long long now=q.front();
            q.pop();
            for(long long i=0;i<m;i++){
                if(p[i].x==now&&b[p[i].y]){
                    ans[p[i].y]=p[i].x;
                    //cout<<p[i].y<<"  "<<ans[p[i].y]<<endl;
                    b[p[i].y]=false;
                    count++;
                    q.push(p[i].y);
                }
                if(p[i].y==now&&b[p[i].x]){
                    ans[p[i].x]=p[i].y;
                    //cout<<p[i].x<<"  "<<ans[p[i].x]<<endl;
                    b[p[i].x]=false;
                    count++;
                    q.push(p[i].x);
                }
            }
        }
        if(count!=n)
            cout<<"No"<<endl;
        else{
            cout<<"Yes"<<endl;
            for(long long i=2;i<=n;i++)
                printf("%lld\n",ans[i]);
        }

    }


    return 0;
}

Compiler output:
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, enum, or record expected
#include <bits/stdc++.h>
         ^
Main.java:2: error: illegal character: '#'
#include <iostream>
^
Main.java:4: error: class, interface, enum, or record expected
long long n,m;
^
Main.java:5: error: class, interface, enum, or record expected
struct Passages{
^
Main.java:7: error: class, interface, enum, or record expected
};
^
Main.java:8: error: class, interface, enum, or record expected
Passages p[200050];
^
Main.java:9: error: class, interface, enum, or record expected
long long ans[200050];
^
Main.java:10: error: class, interface, enum, or record expected
bool b[100500];
^
Main.java:13: error: not a statement
    cin>>n>>m;
          ^
Main.java:14: error: not a statement
    queue<long long>q;
         ^
Main.java:14: error: not a statement
    queue<long long>q;
               ^
Main.java:14: error: not a statement
    queue<long long>q;
                    ^
Main.java:37: error: not a statement
        cout<<"-1";
            ^
Main.java:40: error: not a statement
            long long now=q.front();
            ^
Main.java:42: error: not a statement
            for(long long i=0;i<m;i++){
                ^
Main.java:42: error: not a statement
            for(long long i=0;i<m;i++){
                               ^
Main.java:60: error: not a statement
            cout<<"No"<<endl;
                      ^
Main.java:62: error: not a statement
            cout<<"Yes"<<endl;
                       ^
Main.java:63: error: not a statement
            for(long long i=2;i<=n;i++)
                ^
Main.java:63: error: not a statement
            for(long long i=2;i<=n;i++)
                               ^
Main.java:11: error: unnamed classes are a preview feature and are disabled by default.
int main()
^
  (use --enable-preview to enable unnamed classes)
Main.java:14: error: ';' expected
    queue<long long>q;
                   ^
Main.java:19: error: illegal start of expression
        scanf("%lld%lld", &p[i].x, &p[i].y);
                          ^
Main.java:19: error: illegal start of expression
        scanf("%lld%lld", &p[i].x, &p[i].y);
                                   ^
Main.java:40: error: ';' expected
            long long now=q.front();
                ^
Main.java:42: error: ';' expected
            for(long long i=0;i<m;i++){
                    ^
Main.java:42: error: '.class' expected
            for(long long i=0;i<m;i++){
                          ^
Main.java:42: error: ')' expected
            for(long long i=0;i<m;i++){
                             ^
Main.java:42: error: > or ',' expected
            for(long long i=0;i<m;i++){
                                 ^
Main.java:42: error: ';' expected
            for(long long i=0;i<m;i++){
                                     ^
Main.java:63: error: ';' expected
            for(long long i=2;i<=n;i++)
                    ^
Main.java:63: error: '.class' expected
            for(long long i=2;i<=n;i++)
                          ^
Main.java:63: error: ')' expected
            for(long long i=2;i<=n;i++)
                             ^
Main.java:63: error: ';' expected
            for(long long i=2;i<=n;i++)
                                      ^
35 errors