QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#626796#7007. Rikka with Data StructurestarjenCompile Error//C++201.8kb2024-10-10 13:07:292024-10-10 13:07:29

Judging History

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

  • [2024-10-10 13:07:29]
  • 评测
  • [2024-10-10 13:07:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

void solve()
{
    int n,m,k;cin>>n>>m>>k;
    vector<vector<int>> ve(n+1);
    for(int i=1;i<n;i++){
        int x,y;cin>>x>>y;
        ve[x].push_back(y);
        ve[y].push_back(x);
    }
    vector<int>dep(n+1);
    vector<vector<int>> f(21,vector<int>(n+1));
    function<void(int,int)> dfs1 = [&](int x,int h){
        dep[x]=dep[h]+1;
        for(int i=0;i<=19;i++)
            f[i+1][x]=f[i][f[i][x]];
        for(auto it:ve[x])if(it!=h){
            f[0][it]=x;
            dfs1(it,x);
        }
    };
    dfs1(1,0);
    int ans=0;
    auto lca = [&](int x,int y){
        if(dep[x]<dep[y])swap(x,y);
        for(int i=20;i>=0;i--){
            if(dep[f[i][x]]>=dep[y])x=f[i][x];
            if(x==y)return x;
        }
        for(int i=20;i>=0;i--)
            if(f[i][x]!=f[i][y])
                x=f[i][x],y=f[i][y];
        return f[0][x];
    };
    vector<int> addp(n+1),adde(n+1);
    vector<int> valp(n+1),vale(n+1);
    while(m--){
        int x,y;cin>>x>>y;
        int l=lca(x,y);
        {
            valp[l]++;
            addp[l]-=2;
            addp[x]++;addp[y]++;
        }
        {
            adde[l]-=2;
            adde[x]++;adde[y]++;
        }
    }
    function<void(int,int)> dfs = [&](int x,int h){
        for(auto it:ve[x])if(it!=h){
            dfs(it,x);
            addp[x]+=addp[it];
            adde[x]+=adde[it];
        }
        valp[x]+=addp[x];
        vale[x]+=adde[x];
        add(ans,C(valp[x],k));
        if(x!=1)del(ans,C(vale[x],k));
    };
    dfs(1,0);
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;cin>>T;
    init();
    while(T--)solve();
}

/*
1
3 6 2
1 2
1 3
1 1
2 2
3 3
1 2
1 3
2 3

*/

詳細信息

answer.code: In lambda function:
answer.code:60:17: error: ‘C’ was not declared in this scope
   60 |         add(ans,C(valp[x],k));
      |                 ^
answer.code:60:9: error: ‘add’ was not declared in this scope; did you mean ‘std::filesystem::perm_options::add’?
   60 |         add(ans,C(valp[x],k));
      |         ^~~
      |         std::filesystem::perm_options::add
In file included from /usr/include/c++/13/filesystem:48,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:200,
                 from answer.code:1:
/usr/include/c++/13/bits/fs_fwd.h:211:7: note: ‘std::filesystem::perm_options::add’ declared here
  211 |       add       = 0x2,
      |       ^~~
answer.code:61:17: error: ‘del’ was not declared in this scope; did you mean ‘dep’?
   61 |         if(x!=1)del(ans,C(vale[x],k));
      |                 ^~~
      |                 dep
answer.code: In function ‘void solve()’:
answer.code:64:12: error: return-statement with a value, in function returning ‘void’ [-fpermissive]
   64 |     return ans;
      |            ^~~
answer.code: In function ‘int main()’:
answer.code:72:5: error: ‘init’ was not declared in this scope; did you mean ‘int’?
   72 |     init();
      |     ^~~~
      |     int