版本比较
点分治
正文
增加 8 行删除 8 行
183 行未改动全部展开18418518618718818919019119256 行未改动24925025125225325425525625731 行未改动2892902912922932942952962972982993003013023033043053063073083093103113123133143153163175 行未改动3233243253263273283293303315 行未改动33733833934034134234334434525 行未改动183 行未改动全部展开}q1.add(q2[cur].get_res());//将该点信息汇总到q1}inline void modify(int cur, int type) {//type: 0:add; 1:delq1.del(q2[cur].get_res());type ? q2[cur].del(0) : q2[cur].add(0);//change itselfq1.add(q2[cur].get_res());int np = cur;56 行未改动int np = cur, id = dis[cur].size() - 1;//id:attentionwhile (dfzfa[np]) {int faa = dfzfa[np]; q1.del(q2[faa].get_res());int tmp = q3[np].top(); if (tmp != -inf) q2[faa].del(tmp);type ? q3[np].del(dis[cur][id]) : q3[np].add(dis[cur][id]);//dis[][]!!tmp = q3[np].top(); if (tmp != -inf) q2[faa].add(tmp);q1.add(q2[faa].get_res());np = dfzfa[np]; --id; //id-- !!!}31 行未改动关键代码:```cppvoid dfs(int cur) {dtot = 0;fg = true;//打了fg将会把 dfs 到的点的 dis 都存到其 vec 里dfs_dis(cur, 0, 0);fg = false;lim1[cur] = dtot;build(0, dtot, rt1[cur]);vis[cur] = true;for (register int i = head[cur]; i; i = e[i].nxt) {int to = e[i].to; if (vis[to]) continue;Siz = siz[to], mxSiz = n;find_root(to, 0);int nwroot = root;fa[root] = cur;dtot = 0;dfs_dis(to, 0, 1);lim2[nwroot] = dtot;build(0, dtot, rt2[nwroot]);dfs(nwroot);}}5 行未改动int nwt = vec[p].size() - 2;while (nw) {modify(0, lim1[nw], vec[p][nwt], cha, rt1[nw]);modify(0, lim2[lst], vec[p][nwt], cha, rt2[lst]);lst = nw, nw = fa[nw]; --nwt;}}5 行未改动if (k - vec[p][nwt] >= 0) {//Attention!!!res += query(0, lim1[nw], 0, k - vec[p][nwt], rt1[nw]);res -= query(0, lim2[lst], 0, k - vec[p][nwt], rt2[lst]);}lst = nw, nw = fa[nw], --nwt;}return res;}25 行未改动183 行未改动全部展开18418518618718818919019119256 行未改动24925025125225325425525625731 行未改动2892902912922932942952962972982993003013023033043053063073083093103113123133143153163175 行未改动3233243253263273283293303315 行未改动33733833934034134234334434525 行未改动183 行未改动全部展开}q1.add(q2[cur].get_res());//将该点信息汇总到q1}inline void modify(int cur, int type) {//type: 0:add; 1:delq1.del(q2[cur].get_res());type ? q2[cur].del(0) : q2[cur].add(0);//change itselfq1.add(q2[cur].get_res());int np = cur;56 行未改动int np = cur, id = dis[cur].size() - 1;//id:attentionwhile (dfzfa[np]) {int faa = dfzfa[np]; q1.del(q2[faa].get_res());int tmp = q3[np].top(); if (tmp != -inf) q2[faa].del(tmp);type ? q3[np].del(dis[cur][id]) : q3[np].add(dis[cur][id]);//dis[][]!!tmp = q3[np].top(); if (tmp != -inf) q2[faa].add(tmp);q1.add(q2[faa].get_res());np = dfzfa[np]; --id; //id-- !!!}31 行未改动关键代码:```cppvoid dfs(int cur) {dtot = 0;fg = true;//打了fg将会把 dfs 到的点的 dis 都存到其 vec 里dfs_dis(cur, 0, 0);fg = false;lim1[cur] = dtot;build(0, dtot, rt1[cur]);vis[cur] = true;for (register int i = head[cur]; i; i = e[i].nxt) {int to = e[i].to; if (vis[to]) continue;Siz = siz[to], mxSiz = n;find_root(to, 0);int nwroot = root;fa[root] = cur;dtot = 0;dfs_dis(to, 0, 1);lim2[nwroot] = dtot;build(0, dtot, rt2[nwroot]);dfs(nwroot);}}5 行未改动int nwt = vec[p].size() - 2;while (nw) {modify(0, lim1[nw], vec[p][nwt], cha, rt1[nw]);modify(0, lim2[lst], vec[p][nwt], cha, rt2[lst]);lst = nw, nw = fa[nw]; --nwt;}}5 行未改动if (k - vec[p][nwt] >= 0) {//Attention!!!res += query(0, lim1[nw], 0, k - vec[p][nwt], rt1[nw]);res -= query(0, lim2[lst], 0, k - vec[p][nwt], rt2[lst]);}lst = nw, nw = fa[nw], --nwt;}return res;}25 行未改动