https://www.acmicpc.net/problem/1389
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
static int arr[101][101];
static bool check[101];
static int n;
static void set(){
for(int i=0;i<=n;i++){
check[i]=false;
}
}
static int bfs(int a){
set();
queue<pair<int,int>> q;
q.push(make_pair(a,0));
check[a]=true;
int sum=0;
while(!q.empty()){
int v1=q.front().first;
int v2=q.front().second;
q.pop();
sum+=v2;
for(int i=1;i<=n;i++){
if(arr[v1][i]==1 && check[i]==false){
check[i]=true;
q.push(make_pair(i,v2+1));
}
}
}
return sum;
}
int main() {
int m;
cin >> n >> m;
while(m-->0){
int a,b;
cin >> a >> b;
arr[a][b]=arr[b][a]=1;
}
int count=1000;
int ans=0;
for(int i=1;i<=n;i++){
int sum=bfs(i);
if(count>sum){
count=sum;
ans=i;
}
}
cout << ans;
}