QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#369560 | #143. 最大流(随机数据) | Isrothy | Compile Error | / | / | C++23 | 2.4kb | 2024-03-28 14:28:29 | 2024-03-28 14:28:31 |
Judging History
answer
#include <cstdint>
#include <cstdio>
#include <numbers>
#include <queue>
#include <vector>
struct Dinic {
static const int INF = INT_MAX;
struct Edge {
size_t from, to;
int cap, flow;
Edge(size_t u, size_t v, int 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, int 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, int 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) {
int flow = 0;
while (bfs(s, t)) {
std::fill(cur.begin(), cur.end(), 0);
flow += dfs(s, t, INF);
}
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;
int c;
scanf("%zu%zu%d", &u, &v, &c);
dinic.add_edge(u, v, c);
}
printf("%d\n", dinic.max_flow(s, t));
return 0;
}
Details
answer.code:7:28: error: ‘INT_MAX’ was not declared in this scope 7 | static const int INF = INT_MAX; | ^~~~~~~ answer.code:5:1: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’? 4 | #include <queue> +++ |+#include <climits> 5 | #include <vector> answer.code: In function ‘int main()’: answer.code:75:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 75 | scanf("%zu%zu%zu%zu", &n, &m, &s, &t); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ answer.code:80:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 80 | scanf("%zu%zu%d", &u, &v, &c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~