제출 #1299950

#제출 시각아이디문제언어결과실행 시간메모리
1299950LaMatematica14Split the Attractions (IOI19_split)C++17
컴파일 에러
0 ms0 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; vector<int> find_split(int n, int A, int B, int C, vector<int> P, vector<int> Q) { array<pair<int, int>, 3> att; att[0] = {A, 1}; att[1] = {B, 2}; att[2] = {C, 3}; sort(att.begin(), att.end()); A = att[0].first; B = att[1].first; C = att[2].first; vector<int> sz(n, 1); vector<vector<int>> adj(n); vector<int> p(n); vector<int> vis(n, 0); vector<int> hgh(n); vector<int> dpth(n, 0); for (size_t i = 0; i < P.size(); i++) { adj[P[i]].push_back(Q[i]); adj[Q[i]].push_back(P[i]); } int base = 0; function<void(int)> dfs = [&](int a) { if (base > 0) return; bool ok = 1; vis[a] = 1; hgh[a] = dpth[a]; for (int x : adj[a]) { if (vis[x]) { if (x != p[a]) hgh[a] = min(hgh[a], dpth[x]); continue; } p[x] = a; dpth[x] = dpth[a]+1; dfs(x); sz[a] += sz[x]; if (sz[x] >= A) { ok = 0; } } if (sz[a] < A) ok = 0; if (ok) { int aus = n-sz[a]; base = a; for (int x : adj[a]) { if (x == 0 || p[x] != a) continue; if (aus >= A && n-aus >= A) break; if (hgh[x] < dpth[a]) aus += sz[x]; p[x] = p[a]; } if (aus < A || n-aus < A) base = -1; } }; p[0] = -1; dfs(0); if (base <= 0) return vector<int> (n, 0); vis = vector<int> (n, -1); int ja = 0, jb = 0; function<void(int, int, int)> dfsa = [&](int a, int tg, int sign) { if (ja < tg) { vis[a] = sign; ja++; } else return; for (int x : adj[a]) { if (x == 0 || p[x] != a) continue; dfsa(x, tg, sign); } }; function<void(int, int, int)> dfsb = [&](int a, int tg, int sign) { vis[a] = 0; if (jb < tg) { vis[a] = sign; jb++; } else return; for (int x : adj[a]) { if (vis[x] >= 0) continue; dfsb(x); } }; dfsa(base, A, att[0].second); dfsb(p[base], B, att[1].second); if (ja != A || jb != B) { vis = vector<int> (n, -1); int ja = 0, jb = 0; dfsa(base, B, att[1].second); dfsb(p[base], A, att[0].second); } for (int i = 0; i < n; i++) { if (vis[i] <= 0) vis[i] = att[2].second; } return vis; }

컴파일 시 표준 에러 (stderr) 메시지

split.cpp: In lambda function:
split.cpp:87:29: error: no match for call to '(std::function<void(int, int, int)>) (int&)'
   87 |                         dfsb(x);
      |                         ~~~~^~~
In file included from /usr/include/c++/13/functional:59,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from split.cpp:2:
/usr/include/c++/13/bits/std_function.h:587:7: note: candidate: '_Res std::function<_Res(_ArgTypes ...)>::operator()(_ArgTypes ...) const [with _Res = void; _ArgTypes = {int, int, int}]'
  587 |       operator()(_ArgTypes... __args) const
      |       ^~~~~~~~
/usr/include/c++/13/bits/std_function.h:587:7: note:   candidate expects 3 arguments, 1 provided