QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506573#9102. Zayin and ElementsWorldFinalEscapedCompile Error//C++203.1kb2024-08-05 19:42:172024-08-05 19:42:19

Judging History

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

  • [2024-08-05 19:42:19]
  • 评测
  • [2024-08-05 19:42:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 505;

vector<int> adj[N];
int n, m, ntot;

void addedge(int u, int v) {
    adj[u].push_back(v);
    adj[v].push_back(u);
}

int link[N], mate[N], bel[N], vis[N], cur;
int q[N], type[N], t;
int getLCA(int u, int v) {
    for (++cur; ; swap(u, v)) {
        if (u) {
            if (vis[u] == cur) return u;
            vis[u] = cur, u = bel[link[mate[u]]];
        }
    }
}
void upward(int u, int v, int target) {
    while (bel[u] != target) {
        link[u] = v;
        if (type[mate[u]] == 1)
            q[++t] = mate[u], type[mate[u]] = 0;
        if (bel[u] == u)
            bel[u] = target;
        if (bel[mate[u]] == mate[u])
            bel[mate[u]] = target;
        v = mate[u], u = link[v];
    }
}
bool match(int ver) {
    q[t = 1] = ver;
    for (int u = 1; u <= ntot; u++)
        bel[u] = u, type[u] = -1;
    type[ver] = 0;
    for (int i = 1; i <= t; i++) {
        int u = q[i];
        for (auto v: adj[u]) {
            if (!~type[v]) {
                link[v] = u, type[v] = 1;
                int nu = mate[v];
                if (!nu) {
                    while (v) {
                        int nv = mate[link[v]];
                        mate[v] = link[v], mate[link[v]] = v;
                        v = nv;
                    }
                    return true;
                }
                q[++t] = nu, type[nu] = 0;
            } else if (!type[v] && bel[u] != bel[v]) {
                int lca = getLCA(u, v);
                upward(u, v, lca), upward(v, u, lca);
                for (int u = 1; u <= ntot; u++)
                    bel[u] = bel[bel[u]];
            }
        }
    }
    return false;
}

void sc() {
    memset(link, 0, sizeof(link));
    memset(mate, 0, sizeof(mate));
    memset(bel, 0, sizeof(bel));
    while (ntot) {
        adj[ntot].clear();
        ntot--;
    }

    scanf("%d", &n);
    scanf("%d", &m);
    ntot = n + m;
    for (int i = 1; i <= m; i++) {
        int a, b, c; scanf("%d%d%d", &a, &b, &c);
        int len; scanf("%d", &len);
        vector<int> to;
        for (int j = 0; j < len; j++) {
            int x; scanf("%d", &x);
            to.push_back(x);
        }
        while (a--) {
            ++ntot;
            for (auto it: to) addedge(ntot, it);
        }
        b *= 2;
        while (b--) {
            ++ntot;
            if (b % 2 == 0) addedge(ntot - 1, ntot);
            for (auto it: to) addedge(ntot, it);
        }
        while (c--) {
            ++ntot, ++ntot;
            addedge(ntot - 1, ntot);
            for (auto it: to) addedge(ntot, it);
        }
    }
    int ans = 0;
    for (int i = 1; i <= ntot; i++) {
        if (mate[i]) continue;
        if (match(i)) {
            ans++;
        } else if (i <= n) {
            puts("-1");
            return ;
        }
    }
    printf("%d\n", ans - n);
}

int main() {
    int T; scanf("%d", &T);
    while (T--) sc();
    return 0;
}

/*
2
5
2
2 3 1 2 3 1
1 1 1 3 4 5 2

5
2
2 3 1 1 3
1 0 1 2 1 2
*/

详细

answer.code:14:11: error: ‘int link [505]’ redeclared as different kind of entity
   14 | int link[N], mate[N], bel[N], vis[N], cur;
      |           ^
In file included from /usr/include/c++/13/bits/atomic_wait.h:44,
                 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 answer.code:1:
/usr/include/unistd.h:789:12: note: previous declaration ‘int link(const char*, const char*)’
  789 | extern int link (const char *__from, const char *__to)
      |            ^~~~
answer.code: In function ‘int getLCA(int, int)’:
answer.code:20:47: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   20 |             vis[u] = cur, u = bel[link[mate[u]]];
      |                                               ^
answer.code:20:34: error: invalid types ‘int [505][int(const char*, const char*) noexcept]’ for array subscript
   20 |             vis[u] = cur, u = bel[link[mate[u]]];
      |                                  ^
answer.code: In function ‘void upward(int, int, int)’:
answer.code:26:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   26 |         link[u] = v;
      |               ^
answer.code:26:17: error: assignment of read-only location ‘*(link + ((sizetype)u))’
   26 |         link[u] = v;
      |         ~~~~~~~~^~~
answer.code:33:32: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   33 |         v = mate[u], u = link[v];
      |                                ^
answer.code:33:32: error: invalid conversion from ‘int (*)(const char*, const char*) noexcept’ to ‘int’ [-fpermissive]
   33 |         v = mate[u], u = link[v];
      |                          ~~~~~~^
      |                                |
      |                                int (*)(const char*, const char*) noexcept
answer.code: In function ‘bool match(int)’:
answer.code:45:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   45 |                 link[v] = u, type[v] = 1;
      |                       ^
answer.code:45:25: error: assignment of read-only location ‘*(link + ((sizetype)v))’
   45 |                 link[v] = u, type[v] = 1;
      |                 ~~~~~~~~^~~
answer.code:49:45: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   49 |                         int nv = mate[link[v]];
      |                                             ^
answer.code:49:38: error: invalid types ‘int [505][int(const char*, const char*) noexcept]’ for array subscript
   49 |                         int nv = mate[link[v]];
      |                                      ^
answer.code:50:41: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   50 |                         mate[v] = link[v], mate[link[v]] = v;
      |                                         ^
answer.code:50:41: error: invalid conversion from ‘int (*)(const char*, const char*) noexcept’ to ‘int’ [-fpermissive]
   50 |                         mate[v] = link[v], mate[link[v]] = v;
      |                                   ~~~~~~^
      |                                         |
      |                                         int (*)(const char*, const char*) noexcept
answer.code:50:55: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   50 |                         mate[v] = link[v], mate[link[v]] = v;
      |                                                       ^
answer.code:50:48: error: invalid types ‘int [505][int(const char*, const char*) noexcept]’ for array subscript
   50 |                         mate[v] = link[v], mate[link[v]] = v;
      |                                                ^
answer.code: In function ‘void sc()’:
answer.code:68:28: error: ISO C++ forbids applying ‘sizeof’ to an expression of function type [-fpermissive]
   68 |     memset(link, 0, sizeof(link));
      |                           ~^~~~~
answer.code:68:12: error: invalid conversion from ‘int (*)(const char*, const char*) noexcept’ to ‘void*’ [-fpermissive]
   68 |     memset(link, 0, sizeof(link));
      |            ^~~~
      |            |
      |            int (*)(const char*, const char*) noexcept
In file included from /usr/include/features.h:461,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/c++config.h:679,
                 from /usr/include/c++/13/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:33:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:59:1: note:   initializing argument 1 of ‘void* memset(void*, int, size_t)’
   59 | __NTH (memset (void *__dest, int __ch, size_t __len))
      | ^~~~~
answer.code:76:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘...