#include using namespace std; typedef long long ll; #define REP(i,n) FOR(i,0,n) #define FOR(i,a,b) for(ll i=a;i vi; typedef vector> vvi; const ll INF = (1ll << 30); typedef pair pii; struct Edge{ ll s,t,c; }; typedef vector> Graph; typedef vector vpii; vi getDist(Graph graph,ll r) { ll V=graph.size(); vi dist(V); REP(i,V) dist[i]=INF; priority_queue> pq; dist[r]=0; pq.push({0ll,r}); while(pq.size()){ ll s=pq.top().second; for(ll to:graph[s]) if(dist[to] > dist[s]+1) { dist[to]=dist[s]+1; pq.push({dist[to],to}); } pq.pop(); } return dist; } int main() { ll N,M; cin>>N>>M; Graph G(N); vi a(M),b(M); REP(i,M) cin>>a[i]>>b[i]; REP(i,M) { G[a[i]].PB(b[i]); G[b[i]].PB(a[i]); } unordered_map cnt; REP(i,M) { cnt[a[i]]+=1; cnt[b[i]]+=1; } { vi dist=getDist(G,a[0]); for(auto p:cnt) { if(dist[p.first]==INF) { cout<<"NO"<