QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#150184#5580. Branch ManagerNeriCompile Error//C++231.9kb2023-08-25 15:34:362023-08-25 15:34:38

Judging History

你现在查看的是最新测评结果

  • [2023-08-25 15:34:38]
  • 评测
  • [2023-08-25 15:34:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define nall(x) next((x).begin()), (x).end()
constexpr int mod = 1e9 + 7;
constexpr int M = 500;
constexpr int N = 2e5 + 3;

void init()
{

}
int fa[20][N];
set<int> edge[N];
int dep[N];
bitset<N> vis;

void dfs(int u, int f)
{
    dep[u] = dep[f] + 1;
    for(auto& v : edge[u])
        dfs(v, u);
}
int lca(int u,int v)
{
    if(dep[u] > dep[v])
        swap(u, v);
    int dis = dep[v] - dep[u];

    for(int i = 19;i >= 0;--i)
        if((1 << i) & dis)
            v = fa[i][v];
    if(v == u)
        return u;

    for(int i = 19;i >= 0;--i)
        if(fa[i][u] != fa[i][v])
            u = fa[i][u], v = fa[i][v];
    return fa[0][u];
}

void tag(int u)
{
    vis[u] = true;
    for(auto& v : edge[u])
        dfs(v, u);
}

bool calc(int u,int t)
{

    if(u == t)
        return true;
    for(auto& v : edge[u])
    {
        if(vis[v])
            continue;
        int now = lca(v, t);
        if(now != v)
            vis[v] = 1, tag(v);
        else if(now == v)
            return calc(v, t);
    }
    return false;
}

void slove()
{
    int n, m;
    cin >> n >> m;
   
    int u, v;
    for(int i = 1;i < n;++i)
    {
        cin >> u >> v;
        if(u > v)
            swap(u, v);
        edge[u].insert(v);
        fa[0][v] = u;
    }

    for(int i = 1;i < 20;++i)
        for(int j = 1;j <= n;++j)
            fa[i][j] = fa[i - 1][fa[i - 1][j]];

    dfs(1, 0);


    vector<int> d(m + 1);
    for(int i = 1;i <= m;++i)
        cin >> d[i];

    int tot = 0;
    for(int i = 1;i <= m;++i)

        if(!vis[d[i]] && calc(1, d[i]))
            ++tot,ne[d[i]] = 1;
        else
            break;
    cout << tot << endl;
}
signed main()
{
    cin.tie(0)->sync_with_stdio(false);
    int t = 1;
  
    init();
    while(t--)
        slove();
    return 0;
}

详细

answer.code: In function ‘void slove()’:
answer.code:98:19: error: ‘ne’ was not declared in this scope; did you mean ‘n’?
   98 |             ++tot,ne[d[i]] = 1;
      |                   ^~
      |                   n