queue<pair<int, int» q; q.push(0, 0); while (v, d) := q.pop() { if d == target: ans += val[v] continue if left[v] q.push(left[v], d+1) if right[v] q.push(right[v], d+1) }
queue<pair<int, int» q; q.push(0, 0); while (v, d) := q.pop() { if d == target: ans += val[v] continue if left[v] q.push(left[v], d+1) if right[v] q.push(right[v], d+1) }
queue<pair<int, int» q; q.push(0, 0); while (v, d) := q.pop() { if d == target: ans += val[v] continue if left[v] q.push(left[v], d+1) if right[v] q.push(right[v], d+1) }
queue<pair<int, int» q; q.push(0, 0); while (v, d) := q.pop() { if d == target: ans += val[v] continue if left[v] q.push(left[v], d+1) if right[v] q.push(right[v], d+1) }