版本比较
2022[USACODEC]Barn Tree S
正文
增加 7 行删除 7 行
14 行未改动151617181919202122234 行未改动282930313233323334353637383940414243434445464748494950515251525354555614 行未改动14 行未改动const int N = 2E5 + 5;int n, u, v;/*up:pushup the things down:pushdown the things*/ */vector<LL> G[N], x, y, c;LL h[N], ave, dis[N];void newop(int from, int to, LL val) {//新操作 x.push_back(from);4 行未改动 dis[u] = h[u] - ave; for (int v: G[u]) { if (v == f) continue; calc(v, u); dis[u] += dis[v]; } dis[u] += dis[v]; }}void dfs(int u, int f) {//构造运输方案 for (int v: G[u]) {//干草>平均值 if (v == f) continue; if (dis[v] > 0) { dfs(v, u); newop(v, u, dis[v]); } if (dis[v] == 0) dfs(v, u); } } for (int v: G[u]) {//干草<平均值 if (v == f) continue; if (dis[v] < 0) { h[v] -= dis[v]; newop(u, v, -dis[v]); dfs(v, u); dfs(v, u); } } }
}int main(){ scanf("%d", &n);14 行未改动