#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector> Graph(N); for(int i=0; i> u >> v; u--; v--; Graph.at(u).push_back(v); Graph.at(v).push_back(u); } vector> ko1(N),ko2(N); vector par(N,-1); auto d1 = [&](auto d1,int pos,int back) -> pair { int w = 0,b = 1; int siz = Graph.at(pos).size(); for(int i=0; i void { if(back != -1) ko1.at(pos).at(par.at(pos)) = max(pb,pw), ko2.at(pos).at(par.at(pos)) = pw; int siz = Graph.at(pos).size(); vector l1 = ko1.at(pos),r1 = ko1.at(pos),l2 = ko2.at(pos),r2 = ko2.at(pos); for(int i=1; i=0; i--) r1.at(i) += r1.at(i+1),r2.at(i) += r2.at(i+1); answer = min(answer,l2.back()+1); for(int i=0; i