QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#369557 | #143. 最大流(随机数据) | Isrothy | Compile Error | / | / | C++23 | 2.5kb | 2024-03-28 14:23:25 | 2024-03-28 14:24:05 |
Judging History
answer
#include <cstdint>
#include <cstdio>
#include <numbers>
#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:67:61: error: incomplete type ‘std::numeric_limits<long int>’ used in nested name specifier 67 | flow += dfs(s, t, std::numeric_limits<int64_t>::max()); | ^~~ answer.code: In function ‘int main()’: answer.code:79:25: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 4 has type ‘int64_t*’ {aka ‘long int*’} [-Wformat=] 79 | scanf("%zu%zu%lld", &u, &v, &c); | ~~~^ ~~ | | | | | int64_t* {aka long int*} | long long int* | %ld answer.code:82:16: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘long int’ [-Wformat=] 82 | printf("%lld\n", dinic.max_flow(s, t)); | ~~~^ ~~~~~~~~~~~~~~~~~~~~ | | | | long long int long int | %ld answer.code:74:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 74 | scanf("%zu%zu%zu%zu", &n, &m, &s, &t); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ answer.code:79:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 79 | scanf("%zu%zu%lld", &u, &v, &c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~