Submission #776223

# Submission time Handle Problem Language Result Execution time Memory
776223 2023-07-07T13:11:42 Z eltu0815 Jail (JOI22_jail) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define MAX 500005
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
 
using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
 
int n, m, tt;
int parent[120005][25];
int s[120005], t[120005], dep[120005];
vector<int> graph[120005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> tt;
    while(tt--) {
        cin >> n;
        for(int i = 1; i <= n; ++i) graph[i].clear();
        for(int i = 1; i <= n; ++i) for(int j = 0; j <= 20; ++j) parent[i][j] = 0;
        for(int i = 1; i <= n - 1; ++i) {
            int a, b; cin >> a >> b;
            graph[a].push_back(b);
            graph[b].push_back(a);
        }
        
        cin >> m;
        for(int i = 1; i <= m; ++i) cin >> s[i] >> t[i];
        
        auto dfs = [](auto&& self, int node, int par) -> void {
            parent[node][0] = par; dep[node] = dep[par] + 1;
            for(auto v : graph[node]) if(v != par) self(self, v, node);
        };
        dfs(dfs, 1, 0);
        for(int j = 1; j < 20; ++j) for(int i = 1; i <= n; ++i) parent[i][j] = parent[parent[i][j - 1]][j - 1];
        
        auto LCA = [](int u, int v) -> int {
            if(dep[u] < dep[v]) swap(u, v);
            int diff = dep[u] - dep[v], j = 0;
            while(diff) {
                if(diff & 1) u = parent[u][j];
                diff >>= 1; ++j;
            }
            if(u == v) return u;
            for(int i = 19; i >= 0; --i) {
                if(parent[u][i] != parent[v][i]) {
                    u = parent[u][i];
                    v = parent[v][i];
                }
            }
            return parent[u][0];
        };
        
        auto path = [](int s, int t, int n) -> bool {
            while(s != t) {
                if(s == n) return false;
                s = parent[s][0];
            }
            return s == n;
        };
        
        auto chk = [](int s1, int t1, int s2, int t2) -> bool {
            int p1 = LCA(s1, t1), p2 = LCA(s2, t2);
            if(!path(s1, p1, s2) || !path(t1, p1, s2)) return false;
            if(!path(s2, p2, t1) || !path(t2, p2, t1)) return false;
            return true;
        };
        
        if(chk(s[1], t[1], s[2], t[2]) || chk(s[2], t[2], s[1], t[1])) cout << "Yes\n";
        else cout << "No\n";
    }
    
    return 0;
}

Compilation message

jail.cpp: In lambda function:
jail.cpp:68:22: error: 'LCA' is not captured
   68 |             int p1 = LCA(s1, t1), p2 = LCA(s2, t2);
      |                      ^~~
jail.cpp:67:21: note: the lambda has no capture-default
   67 |         auto chk = [](int s1, int t1, int s2, int t2) -> bool {
      |                     ^
jail.cpp:42:14: note: 'main()::<lambda(int, int)> LCA' declared here
   42 |         auto LCA = [](int u, int v) -> int {
      |              ^~~
jail.cpp:69:17: error: 'path' is not captured
   69 |             if(!path(s1, p1, s2) || !path(t1, p1, s2)) return false;
      |                 ^~~~
jail.cpp:67:21: note: the lambda has no capture-default
   67 |         auto chk = [](int s1, int t1, int s2, int t2) -> bool {
      |                     ^
jail.cpp:59:14: note: 'main()::<lambda(int, int, int)> path' declared here
   59 |         auto path = [](int s, int t, int n) -> bool {
      |              ^~~~
jail.cpp:69:38: error: 'path' is not captured
   69 |             if(!path(s1, p1, s2) || !path(t1, p1, s2)) return false;
      |                                      ^~~~
jail.cpp:67:21: note: the lambda has no capture-default
   67 |         auto chk = [](int s1, int t1, int s2, int t2) -> bool {
      |                     ^
jail.cpp:59:14: note: 'main()::<lambda(int, int, int)> path' declared here
   59 |         auto path = [](int s, int t, int n) -> bool {
      |              ^~~~
jail.cpp:70:17: error: 'path' is not captured
   70 |             if(!path(s2, p2, t1) || !path(t2, p2, t1)) return false;
      |                 ^~~~
jail.cpp:67:21: note: the lambda has no capture-default
   67 |         auto chk = [](int s1, int t1, int s2, int t2) -> bool {
      |                     ^
jail.cpp:59:14: note: 'main()::<lambda(int, int, int)> path' declared here
   59 |         auto path = [](int s, int t, int n) -> bool {
      |              ^~~~
jail.cpp:70:26: error: 'p2' was not declared in this scope; did you mean 'p1'?
   70 |             if(!path(s2, p2, t1) || !path(t2, p2, t1)) return false;
      |                          ^~
      |                          p1
jail.cpp:70:38: error: 'path' is not captured
   70 |             if(!path(s2, p2, t1) || !path(t2, p2, t1)) return false;
      |                                      ^~~~
jail.cpp:67:21: note: the lambda has no capture-default
   67 |         auto chk = [](int s1, int t1, int s2, int t2) -> bool {
      |                     ^
jail.cpp:59:14: note: 'main()::<lambda(int, int, int)> path' declared here
   59 |         auto path = [](int s, int t, int n) -> bool {
      |              ^~~~