社区讨论

RE on subtask #1 #2 #3 求条

P3806【模板】点分治参与者 3已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@mm5p22oi
此快照首次捕获于
2026/02/28 10:20
上周
此快照最后确认于
2026/02/28 10:48
上周
查看原帖
rt,subtask 1 #1 #2 #3 subtask 2 #6 subtask 3 #9
CPP
#include<bits/stdc++.h>

using namespace std;

const int MAXN = 1e6 + 1;

int n, m, a[MAXN], b[MAXN], q[MAXN][2];
vector<int> l;
struct node {
    vector<array<int, 2>> e;
    int b, d, t;
}v[MAXN];
int T(int s, int f, int x) {
    int maxn = 0, p;
    v[x].t = 1;
    for(int i = 0; i < v[x].e.size(); i++) {
        auto y = v[x].e[i];
        if(y[0] == f || v[y[0]].b) {
            continue;
        }
        if(p = T(s, x, y[0])) {
            return p;
        }
        v[x].t += v[y[0]].t, maxn = max(maxn, v[y[0]].t);
    }
    return max(maxn, s - v[x].t) * 2 <= s ? x : 0;
}
void W(int r, int f, int x, int d) {
    for(int i = 1; i <= m; i++) {
        q[i][1] |= (d <= q[i][0] && b[q[i][0] - d] == r);
    }
    v[x].d = d, v[x].t = 1;
    l.push_back(x);
    for(int i = 0; i < v[x].e.size(); i++) {
        auto y = v[x].e[i];
        if(y[0] == f || v[y[0]].b) {
            continue;
        }
        W(r, x, y[0], d + y[1]);
        v[x].t += v[y[0]].t;
    }
}
void D(int x, int s) {
    int r = T(s, 0, x);
    b[0] = r, v[r].b = 1;
    for(int i = 0; i < v[r].e.size(); i++) {
        auto y = v[r].e[i];
        if(!v[y[0]].b) {
            l.clear();
            W(r, r, y[0], y[1]);
            for(int j = 0; j < l.size(); j++) {
                int z = l[j];
                if(v[z].d < MAXN) {
                    b[v[z].d] = r;
                }
            }
        }
    }
    for(int i = 0; i < v[r].e.size(); i++) {
        auto y = v[r].e[i];
        if(v[y[0]].b) {
            continue;
        }
        D(y[0], v[y[0]].t);
    }
}

int main() {
    cin >> n >> m;
    for(int i = 1, x, y, w; i < n; i++) {
        cin >> x >> y >> w;
        v[x].e.push_back({y, w});
        v[y].e.push_back({x, w});
    }
    for(int i = 1; i <= m; i++) {
        cin >> q[i][0];
    }
    D(1, n);
    for(int i = 1; i <= m; i++) {
        cout << (q[i][1] ? "AYE\n" : "NAY\n");
    }
    return 0;
}

回复

2 条回复,欢迎继续交流。

正在加载回复...