Submission #1095783

# Submission time Handle Problem Language Result Execution time Memory
1095783 2024-10-03T07:23:42 Z lampooppp Cat Exercise (JOI23_ho_t4) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

const int N=2e5+10;

int up[N+1][20], h[N+1];
vector<int> adj[N+1];
bool vis[N+1];

void dfs(int x)
{
    vis[u]=1;
    for(int v : adj[u])
    {
        if(vis[v]) continue;
        h[v]=h[u]+1;
        up[v][0]=u;
        for(int i=1;i<20;++i) up[v][i] = up[up[v][i-1]][i-1];
        dfs(v);
    }
}

int lca(int u,int v)
{
    if(h[u]<h[v]) swap(u,v);
    int k = h[u]-h[v];
    for(int i=0;i<20;++i)
    {
        if(k>>i&1) u=up[u][i];
    }
    if(u==v) return u;
    k=__lg(h[u]);
    for(k;k>=0;--k)
    {
        if(up[u][k]!=up[v][k])
        {
            u=up[u][k];
            v=up[v][k];
        }
    }
    return up[u][0];
}

int a[N+1];
int dp[N+1];

int lab[N+1];
int mx[N+1];

int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;++i)
    {
        cin >> a[i];
        lab[i]=-1;
        mx[i]=i;
    }
    for(int i=1;i<n;++i)
    {
        int u,v;
        cin >> u >> v;
        adj[a[u]].push_back(a[v]);
        adj[a[v]].push_back(a[u]);
    }
    h[1]=1;
    dfs(1);
    dp[1]=0;
    for(int i=2;i<=n;++i)
    {
        for(int v : adj[i])
        {
            if(v<i)
            {
                int k = mx[findset(v)];
                dp[i]=max(dp[i],dp[k]+dis(k,i));
                unite(v,i);
            }
        }

    }
}

Compilation message

Main.cpp: In function 'void dfs(int)':
Main.cpp:12:9: error: 'u' was not declared in this scope
   12 |     vis[u]=1;
      |         ^
Main.cpp: In function 'int lca(int, int)':
Main.cpp:33:9: warning: statement has no effect [-Wunused-value]
   33 |     for(k;k>=0;--k)
      |         ^
Main.cpp: In function 'int main()':
Main.cpp:76:28: error: 'findset' was not declared in this scope
   76 |                 int k = mx[findset(v)];
      |                            ^~~~~~~
Main.cpp:77:39: error: 'dis' was not declared in this scope; did you mean 'dfs'?
   77 |                 dp[i]=max(dp[i],dp[k]+dis(k,i));
      |                                       ^~~
      |                                       dfs
Main.cpp:78:17: error: 'unite' was not declared in this scope
   78 |                 unite(v,i);
      |                 ^~~~~