{"problem":{"name":"Distance Sums 2","description":{"content":"Given is a tree with $N$ vertices. The vertices are numbered $1,2,\\ldots ,N$, and the $i$\\-th edge is an undirected edge connecting Vertices $u_i$ and $v_i$. For each integer $i\\,(1 \\leq i \\leq N)$, f","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc220_f"},"statements":[{"statement_type":"Markdown","content":"Given is a tree with $N$ vertices. The vertices are numbered $1,2,\\ldots ,N$, and the $i$\\-th edge is an undirected edge connecting Vertices $u_i$ and $v_i$.\nFor each integer $i\\,(1 \\leq i \\leq N)$, find $\\sum_{j=1}^{N}dis(i,j)$.\nHere, $dis(i,j)$ denotes the minimum number of edges that must be traversed to go from Vertex $i$ to Vertex $j$.\n\n## Constraints\n\n*   $2 \\leq N \\leq 2 \\times 10^5$\n*   $1 \\leq u_i < v_i \\leq N$\n*   The given graph is a tree.\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$\n$u_1$ $v_1$\n$u_2$ $v_2$\n$\\vdots$\n$u_{N-1}$ $v_{N-1}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc220_f","tags":[],"sample_group":[["3\n1 2\n2 3","3\n2\n3\n\nWe have:\n$dis(1,1)+dis(1,2)+dis(1,3)=0+1+2=3$,\n$dis(2,1)+dis(2,2)+dis(2,3)=1+0+1=2$,\n$dis(3,1)+dis(3,2)+dis(3,3)=2+1+0=3$."],["2\n1 2","1\n1"],["6\n1 6\n1 5\n1 3\n1 4\n1 2","5\n9\n9\n9\n9\n9"]],"created_at":"2026-03-03 11:01:14"}}