)
debug 1h无果,求调:
code:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool a[2010][2010];
bool vis[2010];
int main(){
int n,m;
priority_queue <int,vector<int>,greater<int> > q;
cin>>n>>m;
for(int i=1;i<=m;i++){
int x,y;
scanf("%d %d",&x,&y);
if(x==y) continue;
a[x][y]=a[y][x]=1;
}
q.push(1);
vis[1]=1;
while(!q.empty()){
int x=q.top();
q.pop();
cout<<x<<" ";
for(int i=1;i<=n;i++){
if(a[x][i]&&!vis[i]){
q.push(i);
vis[i]=1;
}
}
}
return 0;
}