링크 : https://school.programmers.co.kr/learn/courses/30/lessons/86971
#include <string>
#include <vector>
using namespace std;
vector<int> v[200];
int dfs(int to, int from, int count){
for(int i = 0; i < v[from].size(); i++){
if(v[from][i] != to){
count = dfs(from, v[from][i], count+1);
}
}
return count;
}
int solution(int n, vector<vector<int>> wires) {
int answer = 100;
for (auto w : wires){
v[w[0]].push_back(w[1]);
v[w[1]].push_back(w[0]);
}
for (auto w : wires){
int sum = bfs(w[0], w[1], 1);
int comp = n - (2 * sum);
answer = min(answer, abs(comp));
}
return answer;
}