Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF =1001001001;
using P = pair<int,int>;

vector<vector<int>> table;
vector<bool> visit;
int cnt =0;
bool ok;
vector<int> ans;

void dfs(int num, int b)
{
    visit[num] = true;
    if(num == 0)
    {
        ans[b] = min(ans[b], cnt);
        //cout << cnt << " " << ans[b]<< endl;
        ok = true;
        return;
    }

    for(int target : table[num])
    {
        if(visit[target]) continue;
        cnt++;
        dfs(target, b);
        visit[target] = false;
        cnt--;
    }
}

int main(void) 
{
   int n, m;
   cin >> n >> m;
    ans.resize(n);
    table.resize(n), vector<int>(0);
    visit.resize(n);
   rep(i,m){
       int a, b;
       cin >> a >> b;
       --a; --b;
       table[a].push_back(b);
       table[b].push_back(a);
   }
    rep(i,n) ans[i] = INF;

   rep(i,n)
   {
       if(i == 0) continue;
       rep(j,n) visit[j] = false;
       dfs(i ,i);
       if(!ok) 
       {
           cout << "No" << endl;
           return 0;
       }
       ok = false;
       cnt = 0;
   }

   cout << "Yes" << endl;
   rep(i,n-1) cout << ans[i+1] << endl;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:16:5: error: reference to 'visit' is ambiguous
   16 |     visit[num] = true;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:9:14: note:                 'std::vector<bool> visit'
    9 | vector<bool> visit;
      |              ^~~~~
a.cc:27:12: error: reference to 'visit' is ambiguous
   27 |         if(visit[target]) continue;
      |            ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:9:14: note:                 'std::vector<bool> visit'
    9 | vector<bool> visit;
      |              ^~~~~
a.cc:30:9: error: reference to 'visit' is ambiguous
   30 |         visit[target] = false;
      |         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:9:14: note:                 'std::vector<bool> visit'
    9 | vector<bool> visit;
      |              ^~~~~
a.cc: In function 'int main()':
a.cc:41:5: error: reference to 'visit' is ambiguous
   41 |     visit.resize(n);
      |     ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:9:14: note:                 'std::vector<bool> visit'
    9 | vector<bool> visit;
      |              ^~~~~
a.cc:54:17: error: reference to 'visit' is ambiguous
   54 |        rep(j,n) visit[j] = false;
      |                 ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:9:14: note:                 'std::vector<bool> visit'
    9 | vector<bool> visit;
      |              ^~~~~