제출 #1362809

#제출 시각아이디문제언어결과실행 시간메모리
1362809HishamAlshehri자매 도시 (APIO20_swap)C++20
컴파일 에러
0 ms0 KiB
#include "swap.h"
#include <bits/stdc++.h>

using namespace std;

constexpr int maxn = 400005;

int check[maxn], par[maxn], siz[maxn], weight[maxn], rt[maxn], cnt, n, close[maxn], saad[maxn], jump[maxn][20];
int in[maxn], out[maxn], d[maxn], tim;
bool flag[maxn];
vector<int> adj[maxn];

void make(int v) {
    par[v] = v;
    rt[v] = v;
    siz[v] = 1;
    weight[v] = -1;
    close[v] = -1;
}

int fnd(int v) {
    if (par[v] == v) return v;
    return par[v] = fnd(par[v]);
}

void merge(int v, int u, int w) {
    check[u]++, check[v]++;
    v = fnd(v), u = fnd(u);

    if (v == u) {
        flag[v] = 1;
        adj[cnt + n].push_back(rt[v]);
        rt[v] = cnt + n;
        saad[rt[v]] = 1;
        weight[rt[v]] = w;
        cnt++;
        return;
    }
    if (siz[v] < siz[u]) swap(v, u);
    if (check[u] == 3 || check[v] == 3) flag[v] = 1;

    adj[n + cnt].push_back(rt[v]);
    adj[n + cnt].push_back(rt[u]);
    rt[v] = n + cnt;
    cnt++;
    
    flag[v] |= flag[u];
    saad[rt[v]] = flag[v];
    
    weight[rt[v]] = w;
    par[u] = v;
    siz[v] += siz[u];
}

void dfs(int v) {
    in[v] = tim++;
    // cout << close[v] << ' ' << v << '\n';
    for (int u : adj[v]) {
        if (close[u] < 0) close[u] = 1e9;
        if (saad[u]) close[u] = weight[u];
        close[u] = min(close[u], close[v]);
        d[u] = d[v] + 1;
        jump[u][0] = v;
        dfs(u);
    }
    out[v] = tim++;
}

void build() {
    jump[cnt + n - 1][0] = cnt + n - 1;
    for (int j = 1; j < 20; j++) {
        for (int i = 0; i < n + cnt; i++) jump[i][j] = jump[jump[i][j - 1]][j - 1];
    }
}

int lca(int u, int v) {
    if (d[u] < d[v]) swap(u, v);
    if (in[v] < in[u] && out[v] > out[u]) return v;

    for (int k = 19; k >= 0; k--) {
        int w = jump[v][k];
        if (in[w] < in[u] && out[w] > out[u]) continue;
        v = w;
    }

    return jump[v][0];
}

void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    n = N;
    for (int i = 0; i < M + n; i++) make(i);
    vector<array<int, 3>> e;
    for (int i = 0; i < M; i++) e.push_back({W[i], U[i], V[i]});
    
    sort(e.begin(), e.end());
    reverse(e.begin(), e.end());

    while(e.size()) {
        auto [w, v, u] = e.back();
        e.pop_back();

        merge(u, v, w);
    }

    if (saad[cnt + n - 1]) close[cnt + n - 1] = weight[cnt + n - 1];
    dfs(cnt + n - 1);

    // cout << cnt << '\n';

    // for (int i = 0; i < cnt + n; i++) cout << jump[i][0] << ' ';
    build();
}

int getMinimumFuelCapacity(int X, int Y) {
    int w = lca(X, Y);
    // cout << close[w] << '\n';
  return close[w];
}

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

swap.cpp:8:82: error: 'int close [400005]' redeclared as different kind of entity
    8 | int check[maxn], par[maxn], siz[maxn], weight[maxn], rt[maxn], cnt, n, close[maxn], saad[maxn], jump[maxn][20];
      |                                                                                  ^
In file included from /usr/include/c++/13/bits/atomic_wait.h:45,
                 from /usr/include/c++/13/bits/atomic_base.h:42,
                 from /usr/include/c++/13/bits/shared_ptr_atomic.h:33,
                 from /usr/include/c++/13/memory:81,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:56,
                 from swap.cpp:2:
/usr/include/unistd.h:358:12: note: previous declaration 'int close(int)'
  358 | extern int close (int __fd);
      |            ^~~~~
swap.cpp: In function 'void make(int)':
swap.cpp:18:12: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   18 |     close[v] = -1;
      |            ^
swap.cpp:18:14: error: assignment of read-only location '*(close + ((sizetype)v))'
   18 |     close[v] = -1;
      |     ~~~~~~~~~^~~~
swap.cpp: In function 'void dfs(int)':
swap.cpp:59:20: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   59 |         if (close[u] < 0) close[u] = 1e9;
      |                    ^
swap.cpp:59:22: error: ordered comparison of pointer with integer zero ('int (*)(int)' and 'int')
   59 |         if (close[u] < 0) close[u] = 1e9;
      |             ~~~~~~~~~^~~
swap.cpp:59:34: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   59 |         if (close[u] < 0) close[u] = 1e9;
      |                                  ^
swap.cpp:59:36: error: assignment of read-only location '*(close + ((sizetype)u))'
   59 |         if (close[u] < 0) close[u] = 1e9;
      |                           ~~~~~~~~~^~~~~
swap.cpp:60:29: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   60 |         if (saad[u]) close[u] = weight[u];
      |                             ^
swap.cpp:60:31: error: assignment of read-only location '*(close + ((sizetype)u))'
   60 |         if (saad[u]) close[u] = weight[u];
      |                      ~~~~~~~~~^~~~~~~~~~~
swap.cpp:61:16: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   61 |         close[u] = min(close[u], close[v]);
      |                ^
swap.cpp:61:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   61 |         close[u] = min(close[u], close[v]);
      |                               ^
swap.cpp:61:41: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   61 |         close[u] = min(close[u], close[v]);
      |                                         ^
swap.cpp:61:18: error: assignment of read-only location '*(close + ((sizetype)u))'
   61 |         close[u] = min(close[u], close[v]);
      |         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:105:45: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  105 |     if (saad[cnt + n - 1]) close[cnt + n - 1] = weight[cnt + n - 1];
      |                                             ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
swap.cpp:105:47: error: assignment of read-only location '*(close + (((sizetype)(cnt + n)) + 18446744073709551615))'
  105 |     if (saad[cnt + n - 1]) close[cnt + n - 1] = weight[cnt + n - 1];
      |                            ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:117:17: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  117 |   return close[w];
      |                 ^
swap.cpp:117:17: error: invalid conversion from 'int (*)(int)' to 'int' [-fpermissive]
  117 |   return close[w];
      |                 ^
      |                 |
      |                 int (*)(int)