//木DPっぽい嘘解法 #include #include using namespace std; const int INF = 1e8; int dfs(vector>& G, vector& dist, int pos, int last, int d){ int x = INF; for(int i=0; i> n; vector> G(n); for(int i=0; i> x >> y; x--; y--; G[x].push_back(y); G[y].push_back(x); } vector dist(n, INF); dfs(G,dist, 0,-1,0); for(int i=0; i