#include <string>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
const int MAX = 20001;
int graph[MAX][MAX];
int answer = 0;
int maxroute = 0;
int bfs(int sizes) {
int visited[MAX];
memset(visited, -1, sizeof(visited));
queue<pair<int,int>> q;
q.push(make_pair(1,0));
visited[1] = 1;
while (!q.empty()) {
answer = q.size();
int qsize = q.size();
while (qsize > 0) {
int current = q.front().first;
int count = q.front().second;
q.pop();
for (int k = 0; k <= sizes; k++) {
if (graph[current][k] == 1 && visited[k] == -1) {
q.push(make_pair(k, count + 1));
visited[k] = 1;
}
}
qsize--;
}
}
return answer;
}
int solution(int n, vector<vector<int>> edge) {
memset(graph, -1, sizeof(graph));
for (int i = 0; i < edge.size(); i++)
graph[edge[i][0]][edge[i][1]] = graph[edge[i][1]][edge[i][0]] = 1;
bfs(n);
return answer;
}
프로그래머스