QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369552#143. 最大流(随机数据)IsrothyCompile Error//C++232.4kb2024-03-28 14:21:552024-03-28 14:21:56

Judging History

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

  • [2024-03-28 14:21:56]
  • 评测
  • [2024-03-28 14:21:55]
  • 提交

answer

#include <queue>
#include <vector>
struct Dinic {
    struct Edge {
        size_t from, to;
        int64_t cap, flow;
        Edge(size_t u, size_t v, int64_t c) : from(u), to(v), cap(c), flow(0) {}
    };
    std::vector<Edge> edges;
    std::vector<std::vector<size_t>> adj;
    std::vector<size_t> dis, cur;
    std::vector<bool> vis;
    size_t n;
    explicit Dinic(size_t n) : adj(n), dis(n), cur(n), vis(n), n(n) {}
    void add_edge(size_t u, size_t v, int64_t c) {
        adj[u].push_back(edges.size());
        edges.emplace_back(u, v, c);
        adj[v].push_back(edges.size());
        edges.emplace_back(v, u, 0);
    }
    bool bfs(size_t s, size_t t) {
        std::queue<size_t> q;
        std::fill(vis.begin(), vis.end(), false);
        dis[t] = 0;
        vis[t] = true;
        q.push(t);
        while (!q.empty()) {
            auto u = q.front();
            q.pop();
            for (auto i: adj[u]) {
                const auto &e = edges[i ^ 1];
                if (e.flow < e.cap && !vis[e.from]) {
                    vis[e.from] = true;
                    dis[e.from] = dis[u] + 1;
                    q.push(e.from);
                }
            }
        }
        return vis[s];
    }
    auto dfs(size_t u, size_t t, int64_t a) {
        if (u == t) {
            return a;
        }
        auto m = a;
        for (auto &i = cur[u]; i < adj[u].size(); ++i) {
            auto &e = edges[adj[u][i]];
            if (e.flow < e.cap && vis[e.to] && dis[e.to] == dis[u] - 1) {
                auto f = dfs(e.to, t, std::min(m, e.cap - e.flow));
                e.flow += f;
                edges[adj[u][i] ^ 1].flow -= f;
                m -= f;
                if (!m) {
                    break;
                }
            }
        }
        return a - m;
    }
    auto max_flow(size_t s, size_t t) {
        int64_t flow = 0;
        while (bfs(s, t)) {
            std::fill(cur.begin(), cur.end(), 0);
            flow += dfs(s, t, std::numeric_limits<int64_t>::max());
        }
        return flow;
    }
};
int main() {
    size_t n, m, s, t;
    scanf("%zu%zu%zu%zu", &n, &m, &s, &t);
    Dinic dinic(n + 1);
    for (size_t i = 0; i < m; ++i) {
        size_t u, v;
        int64_t c;
        scanf("%zu%zu%lld", &u, &v, &c);
        dinic.add_edge(u, v, c);
    }
    printf("%lld\n", dinic.max_flow(s, t));


    return 0;
}

Details

answer.code:6:9: error: ‘int64_t’ does not name a type
    6 |         int64_t cap, flow;
      |         ^~~~~~~
answer.code:2:1: note: ‘int64_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’?
    1 | #include <queue>
  +++ |+#include <cstdint>
    2 | #include <vector>
answer.code:7:34: error: ‘int64_t’ has not been declared
    7 |         Edge(size_t u, size_t v, int64_t c) : from(u), to(v), cap(c), flow(0) {}
      |                                  ^~~~~~~
answer.code:15:39: error: ‘int64_t’ has not been declared
   15 |     void add_edge(size_t u, size_t v, int64_t c) {
      |                                       ^~~~~~~
answer.code:41:34: error: ‘int64_t’ has not been declared
   41 |     auto dfs(size_t u, size_t t, int64_t a) {
      |                                  ^~~~~~~
answer.code: In constructor ‘Dinic::Edge::Edge(size_t, size_t, int)’:
answer.code:7:63: error: class ‘Dinic::Edge’ does not have any field named ‘cap’
    7 |         Edge(size_t u, size_t v, int64_t c) : from(u), to(v), cap(c), flow(0) {}
      |                                                               ^~~
answer.code:7:71: error: class ‘Dinic::Edge’ does not have any field named ‘flow’
    7 |         Edge(size_t u, size_t v, int64_t c) : from(u), to(v), cap(c), flow(0) {}
      |                                                                       ^~~~
answer.code: In member function ‘bool Dinic::bfs(size_t, size_t)’:
answer.code:32:23: error: ‘const struct Dinic::Edge’ has no member named ‘flow’
   32 |                 if (e.flow < e.cap && !vis[e.from]) {
      |                       ^~~~
answer.code:32:32: error: ‘const struct Dinic::Edge’ has no member named ‘cap’
   32 |                 if (e.flow < e.cap && !vis[e.from]) {
      |                                ^~~
answer.code: In member function ‘auto Dinic::dfs(size_t, size_t, int)’:
answer.code:48:19: error: ‘struct Dinic::Edge’ has no member named ‘flow’
   48 |             if (e.flow < e.cap && vis[e.to] && dis[e.to] == dis[u] - 1) {
      |                   ^~~~
answer.code:48:28: error: ‘struct Dinic::Edge’ has no member named ‘cap’
   48 |             if (e.flow < e.cap && vis[e.to] && dis[e.to] == dis[u] - 1) {
      |                            ^~~
answer.code:49:53: error: ‘struct Dinic::Edge’ has no member named ‘cap’
   49 |                 auto f = dfs(e.to, t, std::min(m, e.cap - e.flow));
      |                                                     ^~~
answer.code:49:61: error: ‘struct Dinic::Edge’ has no member named ‘flow’
   49 |                 auto f = dfs(e.to, t, std::min(m, e.cap - e.flow));
      |                                                             ^~~~
answer.code:50:19: error: ‘struct Dinic::Edge’ has no member named ‘flow’
   50 |                 e.flow += f;
      |                   ^~~~
answer.code:51:38: error: ‘__gnu_cxx::__alloc_traits<std::allocator<Dinic::Edge>, Dinic::Edge>::value_type’ {aka ‘struct Dinic::Edge’} has no member named ‘flow’
   51 |                 edges[adj[u][i] ^ 1].flow -= f;
      |                                      ^~~~
answer.code: In member function ‘auto Dinic::max_flow(size_t, size_t)’:
answer.code:61:9: error: ‘int64_t’ was not declared in this scope
   61 |         int64_t flow = 0;
      |         ^~~~~~~
answer.code:61:9: note: ‘int64_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’?
answer.code:64:13: error: ‘flow’ was not declared in this scope
   64 |             flow += dfs(s, t, std::numeric_limits<int64_t>::max());
      |             ^~~~
answer.code:66:16: error: ‘flow’ was not declared in this scope
   66 |         return flow;
      |                ^~~~
answer.code: In function ‘int main()’:
answer.code:71:5: error: ‘scanf’ was not declared in this scope
   71 |     scanf("%zu%zu%zu%zu", &n, &m, &s, &t);
      |     ^~~~~
answer.code:75:9: error: ‘int64_t’ was not declared in this scope
   75 |         int64_t c;
      |         ^~~~~~~
answer.code:75:9: note: ‘int64_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’?
answer.code:76:38: error: ‘c’ was not declared in this scope
   76 |         scanf("%zu%zu%lld", &u, &v, &c);
      |                                      ^
answer.code:79:5: error: ‘printf’ was not declared in this scope
   79 |     printf("%lld\n", dinic.max_flow(s, t));
      |     ^~~~~~
answer.code:2:1: note: ‘printf’ is defined in header ‘<cstdio>’; did you forget to ‘#include <cstdio>’?
    1 | #include <queue>
  +++ |+#include <cstdio>
    2 | #include <vector>