QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#353947#7103. Red Black TreeMasterGwxCompile Error//C++142.6kb2024-03-14 19:40:562024-03-14 19:40:57

Judging History

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

  • [2024-03-14 19:40:57]
  • 评测
  • [2024-03-14 19:40:56]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp make_pair
typedef long long ll;
const int N=2e5+5;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const ll INF=1e18+3;
#define DEBUG 
#ifdef DEBUG
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(x)
#else
#define debug(...) {}
#endif
//debug(n,m);debug("a,b");
//double max:0x7f,0x43 min:0xfe 0x c2  int:0x3f 
//运算符 priority  后缀 前缀 */+- 位移 比较 &^| && || 赋值

void solve()
{
    int n,m,q;
    cin>>n>>m>>q;
    vector<bool> a(n+1);
    for(int i=1;i<=m;i++) {
      int x;
      cin>>x;
      a[x]=1;
    }
    vector h(n+1,vector<array<int,2>>());
  
    for(int i=1;i<n;i++){
      int x,y,d;
      cin>>x>>y>>d;
      h[x].push_back({y,d});
      h[y].push_back({x,d});
    }
    int tot=0;
    vector<int> dfn(2*n+5),id(2*n+5),lg2(2*n+5);
    vector<ll> dis(n+1),di(n+1);
    vector f(20,vector<int>(2*n+5));
    auto dfs=[&](auto self,int x,int pre)-> void{
      f[0][++tot]=x;
      dfn[x]=tot;    
      for(auto [y,d]:h[x]){
        if(y==pre) {
          if(a[x]) dis[x]=0; else dis[x]=dis[pre]+d;
          di[x]=di[pre]+d;
          continue;
        }
        self(self,y,x);
        f[0][++tot]=x;
      }
      return;
    };
    auto prelca=[&]()->void{
      for(int i=2;i<=2*n;i++) lg2[i]=lg2[i/2]+1;
      for(int i=1;i<=20;i++){
        int r=(1<<(i-1));
        for(int l=1;l<=2*n-r+1;l++){
          f[i][l]=dfn[f[i-1][l]]>dfn[f[i-1][r+l]]?f[i-1][r+l]:f[i-1][l];
        }
      }
    };
    auto find_lca=[&](int x,int y)->int {
      if(x==y) return x;
      x=dfn[x],y=dfn[y];
      if(x>y) swap(x,y);
      int lg=lg2[y-x+1];
      return dfn[f[lg][x]]>dfn[f[lg][y-(1<<lg)+1]]?f[lg][y-(1<<lg)+1]:f[lg][x];
    };
    dfs(dfs,1,0);
    //cout<<tot<<endl;
    prelca();
    //for(int i=1;i<=23;i++) cout<<f[0][i]<<" "; cout<<endl;
    //for(int i=1;i<=23;i++) cout<<dfn[f[0][i]]<<" "; cout<<endl;
    //cout<<find_lca(4,12)<<endl;
    while(q--){
      int c;
      cin>>c;
      vector<int> qe(c+5);
      for(int i=0;i<c;i++) cin>>qe[i];
      sort(qe.begin(),qe.end(),[&](int x,int y){
        return dis[x]>dis[y];
      });
      ll ans=INF;
      ll dt=di[qe[0]],dq=qe[0];
      for(int i=0;i<c;i++){
        dq=find_lca(dq,qe[i]);
        dt=max(dt,di[qe[i]]);
        ans=min(ans,max(dt-di[dq],dis[qe[i+1]]));
      }
      cout<<ans<<"\n";
    }
    return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  #if 1 
        int T; cin>>T; while(T--) solve();
    #else 
        solve();
    #endif 
  return 0; 
}

Details

answer.code: In function ‘void solve()’:
answer.code:30:12: error: missing template arguments before ‘h’
   30 |     vector h(n+1,vector<array<int,2>>());
      |            ^
answer.code:35:7: error: ‘h’ was not declared in this scope
   35 |       h[x].push_back({y,d});
      |       ^
answer.code:41:12: error: missing template arguments before ‘f’
   41 |     vector f(20,vector<int>(2*n+5));
      |            ^
answer.code: In lambda function:
answer.code:43:7: error: ‘f’ was not declared in this scope
   43 |       f[0][++tot]=x;
      |       ^
answer.code:45:16: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   45 |       for(auto [y,d]:h[x]){
      |                ^
answer.code:45:22: error: ‘h’ was not declared in this scope
   45 |       for(auto [y,d]:h[x]){
      |                      ^
answer.code: In lambda function:
answer.code:61:11: error: ‘f’ was not declared in this scope
   61 |           f[i][l]=dfn[f[i-1][l]]>dfn[f[i-1][r+l]]?f[i-1][r+l]:f[i-1][l];
      |           ^
answer.code: In lambda function:
answer.code:70:18: error: ‘f’ was not declared in this scope
   70 |       return dfn[f[lg][x]]>dfn[f[lg][y-(1<<lg)+1]]?f[lg][y-(1<<lg)+1]:f[lg][x];
      |                  ^