QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#288526#5651. Parmigiana With SeafoodSorting#Compile Error//C++201.2kb2023-12-22 20:39:362023-12-22 20:39:37

Judging History

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

  • [2023-12-22 20:39:37]
  • 评测
  • [2023-12-22 20:39:36]
  • 提交

answer

#include <iostream>
#include <vector>

using namespace std;

const int N = 1e5 + 3;

vector<int> adj[N];
int n;

bool check(int mid){
    int d = -1;
    bool ok = true;

    function<void(int, int, int)> dfs = [&](int u, int p, int depth){
        if(u >= mid){
            if(d == -1){
                d = depth;
            }
            else{
                if(d != depth){
                    ok = false;
                }
            }
        }

        for(int to: adj[u]){
            if(to == p) continue;
            dfs(to, u, depth ^ 1);
        }
    };

    dfs(1, -1, 0);
    return ok;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 0; i < n - 1; ++i){
        int x, y;
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    if(n % 2 == 0){
        cout << n << "\n";
        return 0;
    }

    int l = 1, r = n;
    for(int i = 1; i <= n; ++i){
        if(adj[i].size() == 1){
            l = max(l, i);
        }
    }

    while(l != r){
        int mid = (l + r + 1) / 2;
        if(check(mid)) l = mid;
        else r = mid - 1;
    }

    cout << l << "\n";
}

Details

answer.code: In function ‘bool check(int)’:
answer.code:15:5: error: ‘function’ was not declared in this scope
   15 |     function<void(int, int, int)> dfs = [&](int u, int p, int depth){
      |     ^~~~~~~~
answer.code:3:1: note: ‘std::function’ is defined in header ‘<functional>’; did you forget to ‘#include <functional>’?
    2 | #include <vector>
  +++ |+#include <functional>
    3 | 
answer.code:15:32: error: expression list treated as compound expression in functional cast [-fpermissive]
   15 |     function<void(int, int, int)> dfs = [&](int u, int p, int depth){
      |                                ^
answer.code:15:14: error: expected primary-expression before ‘void’
   15 |     function<void(int, int, int)> dfs = [&](int u, int p, int depth){
      |              ^~~~
answer.code:33:5: error: ‘dfs’ was not declared in this scope
   33 |     dfs(1, -1, 0);
      |     ^~~