Submission #576918

# Submission time Handle Problem Language Result Execution time Memory
576918 2022-06-13T19:20:21 Z PagodePaiva Pictionary (COCI18_pictionary) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#define ms(v) memset(v, -1, sizeof v)
#define pb push_back
#define mp make_pair
#define N 200010
using namespace std;

int n, m, q;
int pai[N], edge[N], sz[N], lvl[N];

void init(int x){
    pai[x] = x;
    sz[x] = 1;
}

int find(int x){
    return (x == pai[x] ? x : find(pai[x]));
}

void join(int a, int b, int d){
    a = find(a);
    b = find(b);

    if(a == b) return;

    if(sz[a] < sz[b]) swap(a, b);

    pai[b] = a;
    sz[a] += sz[b];
    edge[b] = d;  

    return;
}

int lca(int a){
    return lvl[a] = (a == pai[a] ? 0 : lca(pai[a]) + 1);
}

int xdfs(int a, int b){
    if(find(a) != find(b)) return -1;

    int resa = 0, resb = 0;

    if(lvl[a] < lvl[b]) swap(a, b);

    while(lvl[a] > lvl[b]){
        if(resa < edge[a]) resa = edge[a];
        a = pai[a];
    }

    while(a != b){
        if(resa < edge[a]) resa = edge[a];
        if(resb < edge[b]) resb = edge[b];

        a = pai[a];
        b = pai[b];
    }

    return max(resa, resb);
}

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

    cin >> n >> m >>  q;

    for(int i = 1;i <= n;i++){
        init(i);
    }

    for (int i = m; i >= 1; i--)
        for (int j = i; j <= n; j += i) 
            join(j, i, m-i+1);

    for(int i = 1;i <= n;i++) lca(i);

    for(int i = 1;i <= q;i++){
        int a, b;
        cin >> a >> b;
        cout << dfs(a, b) << "\n";
    }

    return 0;
}

Compilation message

pictionary.cpp: In function 'int main()':
pictionary.cpp:80:17: error: 'dfs' was not declared in this scope; did you mean 'xdfs'?
   80 |         cout << dfs(a, b) << "\n";
      |                 ^~~
      |                 xdfs