QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#166937#7103. Red Black TreeOMoonStarsCompile Error//C++143.1kb2023-09-06 21:17:012023-09-06 21:17:02

Judging History

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

  • [2023-09-06 21:17:02]
  • 评测
  • [2023-09-06 21:17:01]
  • 提交

answer

@zhu040510@#include<algorithm>
#include<array>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<unordered_map>
#define fi first
#define se second
#define pb push_back
#define endl '\n'
using namespace std;
using ll=long long;
using db=double;
using pii=pair<int,int>;
const int inf=0x3f3f3f3f;
const int mod=998244353;
const int N=1e5+10,M=20;
bool red[N];//红点
vector<int>g[N],w[N];//邻接表,边权
int nr[N];
ll cost[N];//到最近红祖先的距离
int dep[N];//距根节点距离
int fa[N][M];//二维logn
void dfs1(int u,int f)//当前节点和父节点
{
    dep[u]=dep[f]+1;//深度比父节点多1
    fa[u][0]=f;//第2^0=1个祖先就是父节点
    for(int i=1;i<20;i++)//倍增logn次
        fa[u][i]=fa[fa[u][i-1]][i-1];//第2^i个祖先是第2^(i-1)个祖先的第2^(i-1)个祖先
    for(auto v:g[u])//遍历子节点dfs
        if(v!=f)dfs1(v,u);
}
void dfs2(int u,int f,int r,ll d)//当前节点,父节点,当前距离
{
    if(red[u])r=u,d=0;
    nr[u]=r;
    cost[u]=d;
    for(int i=0;i<g[u].size();i++)
        if(g[u][i]!=f)
            dfs2(g[u][i],u,r,d+w[u][i]);
}
int lca(int x,int y)//倍增求x和y的lca节点
{
    if(dep[x]>dep[y])swap(x,y);//令y比x深
    int dist=dep[y]-dep[x];//深度差值
    for(int i=0;dist;i++,dist>>=1)
        if(dist&1)y=fa[y][i];//将深度二进制拆分上跳,令x和y在同一深度
    if(x==y)return x;//已相等说明是祖先
    for(int i=19;x!=y&&~i;i--)
        if(fa[x][i]!=fa[y][i])//找到第一个不是它们祖先的两个点
        {
            x=fa[x][i];//上跳
            y=fa[y][i];
        }
    if(x!=y)x=fa[x][0];//所有次幂祖先均相同则父节点为lca
    return x;//返回最近公共祖先
}
void solve()
{
    int n,m,q;
    cin >> n >> m >> q;
    for(int i=1;i<=n;i++)//初始化
    {
        red[i]=false;
        g[i].clear();
        w[i].clear();
    }
    while(m--)
    {
        int r;
        cin >> r;
        red[r]=true;
    }
    for(int i=1;i<n;i++)
    {
        int u,v,wi;
        cin >> u >> v >> wi;
        g[u].pb(v);
        w[u].pb(wi);
        g[v].pb(u);
        w[v].pb(wi);
    }
    dfs1(1,0);//预处理每点第2的整数次幂个祖先
    dfs2(1,0,1,0);//预处理每个点到最近红祖先的距离
    while(q--)
    {
        int k;
        cin >> k;
        vector<int>v(k);
        for(int i=0;i<k;i++)
        {
            int u;
            cin >> u;
            v.pb(u);
        }
        sort(v.begin(),v.end(),[](int x,int y){
            return cost[x]>cost[y];
        });
        v.pb(0);
        ll ans=cost[v[1]];
        int lc=v[0];
        for(int i=1;i<k;i++)
        {
            lc=lca(lc,v[i]);
            if(dep[lc]<=dep[nr[v[0]]])break;
            ans=min(ans,max(cost[v[0]]-cost[lc],cost[v[i+1]]));
        }
        cout << ans << endl;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while(t--)
        solve();
    return 0;
}

Details

answer.code:1:1: error: stray ‘@’ in program
    1 | @zhu040510@#include<algorithm>
      | ^
answer.code:1:11: error: stray ‘@’ in program
    1 | @zhu040510@#include<algorithm>
      |           ^
answer.code:1:12: error: stray ‘#’ in program
    1 | @zhu040510@#include<algorithm>
      |            ^
answer.code:1:2: error: ‘zhu040510’ does not name a type
    1 | @zhu040510@#include<algorithm>
      |  ^~~~~~~~~
In file included from /usr/include/c++/11/bits/move.h:57,
                 from /usr/include/c++/11/bits/stl_pair.h:59,
                 from /usr/include/c++/11/utility:70,
                 from /usr/include/c++/11/array:38,
                 from answer.code:2:
/usr/include/c++/11/type_traits:227:27: error: ‘size_t’ has not been declared
  227 |   template <typename _Tp, size_t = sizeof(_Tp)>
      |                           ^~~~~~
/usr/include/c++/11/type_traits:431:31: error: ‘std::size_t’ has not been declared
  431 |   template<typename _Tp, std::size_t _Size>
      |                               ^~~~~~
/usr/include/c++/11/type_traits:432:25: error: ‘_Size’ was not declared in this scope
  432 |     struct is_array<_Tp[_Size]>
      |                         ^~~~~
/usr/include/c++/11/type_traits:432:31: error: template argument 1 is invalid
  432 |     struct is_array<_Tp[_Size]>
      |                               ^
/usr/include/c++/11/type_traits:537:42: error: ‘nullptr_t’ is not a member of ‘std’
  537 |     struct __is_null_pointer_helper<std::nullptr_t>
      |                                          ^~~~~~~~~
/usr/include/c++/11/type_traits:537:42: error: ‘nullptr_t’ is not a member of ‘std’
/usr/include/c++/11/type_traits:537:51: error: template argument 1 is invalid
  537 |     struct __is_null_pointer_helper<std::nullptr_t>
      |                                                   ^
/usr/include/c++/11/type_traits:1361:37: error: ‘size_t’ is not a member of ‘std’
 1361 |     : public integral_constant<std::size_t, alignof(_Tp)>
      |                                     ^~~~~~
/usr/include/c++/11/type_traits:1361:37: error: ‘size_t’ is not a member of ‘std’
/usr/include/c++/11/type_traits:1361:57: error: template argument 1 is invalid
 1361 |     : public integral_constant<std::size_t, alignof(_Tp)>
      |                                                         ^
/usr/include/c++/11/type_traits:1361:57: note: invalid template non-type parameter
/usr/include/c++/11/type_traits:1370:37: error: ‘size_t’ is not a member of ‘std’
 1370 |     : public integral_constant<std::size_t, 0> { };
      |                                     ^~~~~~
/usr/include/c++/11/type_traits:1370:37: error: ‘size_t’ is not a member of ‘std’
/usr/include/c++/11/type_traits:1370:46: error: template argument 1 is invalid
 1370 |     : public integral_constant<std::size_t, 0> { };
      |                                              ^
/usr/include/c++/11/type_traits:1370:46: note: invalid template non-type parameter
/usr/include/c++/11/type_traits:1372:31: error: ‘std::size_t’ has not been declared
 1372 |   template<typename _Tp, std::size_t _Size>
      |                               ^~~~~~
/usr/include/c++/11/type_traits:1373:21: error: ‘_Size’ was not declared in this scope
 1373 |     struct rank<_Tp[_Size]>
      |                     ^~~~~
/usr/include/c++/11/type_traits:1373:27: error: template argument 1 is invalid
 1373 |     struct rank<_Tp[_Size]>
      |                           ^
/usr/include/c++/11/type_traits:1374:37: error: ‘size_t’ is not a member of ‘std’
 1374 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                     ^~~~~~
/usr/include/c++/11/type_traits:1374:37: error: ‘size_t’ is not a member of ‘std’
/usr/include/c++/11/type_traits:1374:65: error: template argument 1 is invalid
 1374 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                                                 ^
/usr/include/c++/11/type_traits:1374:65: note: invalid template non-type parameter
/usr/include/c++/11/type_traits:1378:37: error: ‘size_t’ is not a member of ‘std’
 1378 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                     ^~~~~~
/usr/include/c++/11/type_traits:1378:37: error: ‘size_t’ is not a member of ‘std’
/usr/include/c++/11/type_traits:1378:65: error: template argument 1 is invalid
 1378 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                                                 ^
/usr/include/c++/11/type_traits:1378:65: note: invalid template non-type parameter
/usr/include/c++/11/type_traits:1383:37: error: ‘size_t’ is not a member of ‘std’
 1383 |     : public integral_constant<std::size_t, 0> { };
      |                                     ^~~~~~
/usr/include/c++/11/type_traits:1383:37: error: ‘size_t’ is not a member of ‘std’
/usr/include/c++/11/type_traits:1383:46: error...