QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#369570 | #602. 最小费用最大流(随机数据) | Isrothy | Compile Error | / | / | C++23 | 3.8kb | 2024-03-28 14:39:21 | 2024-03-28 14:39:22 |
Judging History
This is the latest submission verdict.
- [2024-03-28 14:39:22]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-03-28 14:39:21]
- Submitted
answer
#include <queue>
#include <vector>
struct PrimalDual {
static constexpr int64_t INF = 0x3f3f3f3f3f3f3f3f;
struct Edge {
size_t from, to;
int64_t cap, cost, flow;
Edge(size_t from, size_t to, int64_t cap, int64_t cost)
: from(from), to(to), cap(cap), cost(cost), flow(0) {}
};
std::vector<Edge> edges;
std::vector<std::vector<size_t>> adj;
std::vector<int64_t> dis, h;
std::vector<bool> vis, in_queue;
size_t n;
explicit PrimalDual(size_t n)
: adj(n + 1), dis(n + 1), h(n + 1), vis(n + 1), in_queue(n + 1), n(n) {}
void add_edge(size_t u, size_t v, int64_t cap, int64_t cost) {
adj[u].push_back(edges.size());
edges.emplace_back(u, v, cap, cost);
adj[v].push_back(edges.size());
edges.emplace_back(v, u, 0, -cost);
}
void spfa(size_t t) {
std::queue<size_t> q;
std::vector<bool> in_queue(n + 1, false);
std::fill(dis.begin(), dis.end(), INF);
dis[t] = 0;
in_queue[t] = true;
q.push(t);
while (!q.empty()) {
auto u = q.front();
q.pop();
in_queue[u] = false;
for (auto i: adj[u]) {
const auto &e = edges[i ^ 1];
if (e.flow != e.cap && dis[u] + e.cost < dis[e.from]) {
dis[e.from] = dis[u] + e.cost;
if (!in_queue[e.from]) {
in_queue[e.from] = true;
q.push(e.from);
}
}
}
}
}
void dijkstra(size_t t) {
std::priority_queue<std::pair<int, int>> q;
std::fill(dis.begin(), dis.end(), INF);
dis[t] = 0;
q.emplace(0, t);
while (!q.empty()) {
auto [d, u] = q.top();
q.pop();
if (dis[u] != -d) {
continue;
}
for (auto i: adj[u]) {
const auto &e = edges[i ^ 1];
auto c = dis[u] + e.cost + h[u] - h[e.from];
if (e.flow < e.cap && c < dis[e.from]) {
dis[e.from] = c;
q.emplace(-c, e.from);
}
}
}
}
auto dfs(size_t u, size_t t, int64_t a) {
if (u == t) {
return a;
}
vis[u] = true;
auto m = a;
for (auto i: adj[u]) {
auto &e = edges[i];
if (e.flow < e.cap && !vis[e.to] && h[e.to] == h[u] - e.cost) {
auto f = dfs(e.to, t, std::min(m, e.cap - e.flow));
e.flow += f;
edges[i ^ 1].flow -= f;
m -= f;
if (m == 0) {
break;
}
}
}
return a - m;
}
auto minimum_cost_flow(size_t s, size_t t) {
int64_t flow = 0, cost = 0;
for (spfa(t); dis[s] != INF; dijkstra(t)) {
for (size_t i = 1; i <= n; ++i) {
h[i] += dis[i];
}
while (true) {
std::fill(vis.begin(), vis.end(), false);
if (auto f = dfs(s, t, INF)) {
flow += f;
cost += f * h[s];
} else {
break;
}
}
}
return std::make_pair(flow, cost);
}
};
int main() {
size_t n, m;
scanf("%zu %zu", &n, &m);
PrimalDual pd(n + 1);
for (size_t i = 0; i < m; ++i) {
size_t u, v;
int64_t c, d;
scanf("%zu %zu %llu %llu", &u, &v, &c, &d);
pd.add_edge(u, v, c, d);
}
auto ans = pd.minimum_cost_flow(1, n);
printf("%lld %lld\n", ans.first, ans.second);
return 0;
}
Details
answer.code:4:22: error: ‘int64_t’ does not name a type 4 | static constexpr int64_t INF = 0x3f3f3f3f3f3f3f3f; | ^~~~~~~ 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:9: error: ‘int64_t’ does not name a type 7 | int64_t cap, cost, flow; | ^~~~~~~ answer.code:7:9: note: ‘int64_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’? answer.code:8:38: error: ‘int64_t’ has not been declared 8 | Edge(size_t from, size_t to, int64_t cap, int64_t cost) | ^~~~~~~ answer.code:8:51: error: ‘int64_t’ has not been declared 8 | Edge(size_t from, size_t to, int64_t cap, int64_t cost) | ^~~~~~~ answer.code:13:17: error: ‘int64_t’ was not declared in this scope 13 | std::vector<int64_t> dis, h; | ^~~~~~~ answer.code:13:17: note: ‘int64_t’ is defined in header ‘<cstdint>’; did you forget to ‘#include <cstdint>’? answer.code:13:24: error: template argument 1 is invalid 13 | std::vector<int64_t> dis, h; | ^ answer.code:13:24: error: template argument 2 is invalid answer.code:13:10: error: ‘<expression error>’ in namespace ‘std’ does not name a type 13 | std::vector<int64_t> dis, h; | ^~~~~~~~~~~~~~~ answer.code:18:39: error: ‘int64_t’ has not been declared 18 | void add_edge(size_t u, size_t v, int64_t cap, int64_t cost) { | ^~~~~~~ answer.code:18:52: error: ‘int64_t’ has not been declared 18 | void add_edge(size_t u, size_t v, int64_t cap, int64_t cost) { | ^~~~~~~ answer.code:68:34: error: ‘int64_t’ has not been declared 68 | auto dfs(size_t u, size_t t, int64_t a) { | ^~~~~~~ answer.code: In constructor ‘PrimalDual::Edge::Edge(size_t, size_t, int, int)’: answer.code:9:35: error: class ‘PrimalDual::Edge’ does not have any field named ‘cap’ 9 | : from(from), to(to), cap(cap), cost(cost), flow(0) {} | ^~~ answer.code:9:45: error: class ‘PrimalDual::Edge’ does not have any field named ‘cost’ 9 | : from(from), to(to), cap(cap), cost(cost), flow(0) {} | ^~~~ answer.code:9:57: error: class ‘PrimalDual::Edge’ does not have any field named ‘flow’ 9 | : from(from), to(to), cap(cap), cost(cost), flow(0) {} | ^~~~ answer.code: In constructor ‘PrimalDual::PrimalDual(size_t)’: answer.code:17:23: error: class ‘PrimalDual’ does not have any field named ‘dis’ 17 | : adj(n + 1), dis(n + 1), h(n + 1), vis(n + 1), in_queue(n + 1), n(n) {} | ^~~ answer.code:17:35: error: class ‘PrimalDual’ does not have any field named ‘h’ 17 | : adj(n + 1), dis(n + 1), h(n + 1), vis(n + 1), in_queue(n + 1), n(n) {} | ^ answer.code: In member function ‘void PrimalDual::spfa(size_t)’: answer.code:27:19: error: ‘dis’ was not declared in this scope; did you mean ‘vis’? 27 | std::fill(dis.begin(), dis.end(), INF); | ^~~ | vis answer.code:27:43: error: ‘INF’ was not declared in this scope 27 | std::fill(dis.begin(), dis.end(), INF); | ^~~ answer.code:37:23: error: ‘const struct PrimalDual::Edge’ has no member named ‘flow’ 37 | if (e.flow != e.cap && dis[u] + e.cost < dis[e.from]) { | ^~~~ answer.code:37:33: error: ‘const struct PrimalDual::Edge’ has no member named ‘cap’ 37 | if (e.flow != e.cap && dis[u] + e.cost < dis[e.from]) { | ^~~ answer.code:37:51: error: ‘const struct PrimalDual::Edge’ has no member named ‘cost’ 37 | if (e.flow != e.cap && dis[u] + e.cost < dis[e.from]) { | ^~~~ answer.code:38:46: error: ‘const struct PrimalDual::Edge’ has no member named ‘cost’ 38 | dis[e.from] = dis[u] + e.cost; | ^~~~ answer.code: In member function ‘void PrimalDual::dijkstra(size_t)’: answer.code:49:19: error: ‘dis’ was not declared in this scope; did you mean ‘vis’? 49 | std::fill(dis.begin(), dis.end(), INF); | ^~~ | vis answer.code:49:43: error: ‘INF’ was not declared in this scope 49 | std::fill(dis.begin(), dis.end(), INF); | ...