QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369554#143. 最大流(随机数据)IsrothyCompile Error//C++232.4kb2024-03-28 14:22:562024-03-28 14:22:57

Judging History

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

  • [2024-03-28 14:22:57]
  • 评测
  • [2024-03-28 14:22:56]
  • 提交

answer

#include <cstdint>
#include <cstdio>
#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: In member function ‘auto Dinic::max_flow(size_t, size_t)’:
answer.code:66:61: error: incomplete type ‘std::numeric_limits<long int>’ used in nested name specifier
   66 |             flow += dfs(s, t, std::numeric_limits<int64_t>::max());
      |                                                             ^~~
answer.code: In function ‘int main()’:
answer.code:78:25: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 4 has type ‘int64_t*’ {aka ‘long int*’} [-Wformat=]
   78 |         scanf("%zu%zu%lld", &u, &v, &c);
      |                      ~~~^           ~~
      |                         |           |
      |                         |           int64_t* {aka long int*}
      |                         long long int*
      |                      %ld
answer.code:81:16: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘long int’ [-Wformat=]
   81 |     printf("%lld\n", dinic.max_flow(s, t));
      |             ~~~^     ~~~~~~~~~~~~~~~~~~~~
      |                |                   |
      |                long long int       long int
      |             %ld
answer.code:73:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   73 |     scanf("%zu%zu%zu%zu", &n, &m, &s, &t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:78:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   78 |         scanf("%zu%zu%lld", &u, &v, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~