QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#435301 | #602. 最小费用最大流(随机数据) | iee | Compile Error | / | / | C++14 | 2.5kb | 2024-06-08 19:35:56 | 2024-06-08 19:35:56 |
Judging History
This is the latest submission verdict.
- [2024-06-08 19:35:56]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-06-08 19:35:56]
- Submitted
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
namespace mcmf {
constexpr int N = 5005, inf = 1e18;
int n, S, T;
struct edge { int v, f, c; };
vector<edge> el;
vector<int> e[N];
void add(int u, int v, int f, int c) {
e[u].push_back(el.size());
el.push_back({v, f, c});
e[v].push_back(el.size());
el.push_back({u, 0, -c});
}
bool vis[N];
int dis[N], h[N], level[N];
void spfa() {
queue<int> q;
q.push(S);
for (int i = 1; i <= n; i++) {
vis[i] = 0;
h[i] = inf;
}
h[S] = 0;
while (q.size()) {
int u = q.front();
q.pop();
vis[u] = 0;
for (int i : e[u]) {
auto [v, f, c] = el[i];
if (f && h[v] > h[u] + c) {
h[v] = h[u] + c;
if (!vis[v]) vis[v] = 1, q.push(v);
}
}
}
}
bool dij() {
priority_queue<array<int, 2>, vector<array<int, 2>>, greater<>> q;
for (int i = 1; i <= n; i++) {
vis[i] = 0;
dis[i] = inf;
level[i] = -1;
}
q.push({dis[S] = 0, S});
while (!q.empty()) {
int u = q.top()[1];
q.pop();
if (vis[u]) continue;
vis[u] = 1;
for (int i : e[u]) {
auto [v, f, c] = el[i];
if (f && dis[v] > dis[u] + c + h[u] - h[v]) {
q.push({dis[v] = dis[u] + c + h[u] - h[v], v});
}
}
}
queue<int> Q;
Q.push(S);
level[S] = 0;
while (!Q.empty()) {
int u = Q.front();
Q.pop();
for (int i : e[u]) {
const auto [v, f, c] = el[i];
if (f && dis[v] == dis[u] + c + h[u] - h[v] && level[v] == -1) {
level[v] = level[u] + 1;
Q.push(v);
}
}
}
return dis[T] != inf;
}
int cur[N];
int dinic(int u, int limit) {
if (u == T) return limit;
int flow = 0;
for (int i = cur[u]; i < e[u].size() && flow < limit; i = max(i + 1, cur[u])) {
cur[u] = i + 1;
auto &[v, f, c] = el[e[u][i]];
if (f && h[v] == h[u] + c && level[v] == level[u] + 1) {
int fl = dinic(v, min(limit - flow, f));
f -= fl;
el[e[u][i] ^ 1].f += fl;
flow += fl;
if (!fl) level[v] = -1;
}
}
return flow;
}
pair<int, int> flow() {
int flow = 0, cost = 0;
// spfa();
while (dij()) {
for (int i = 1; i <= n; i++) {
h[i] = min(h[i] + dis[i], inf);
cur[i] = 0;
}
int f = dinic(S, inf);
flow += f;
cost += f * h[T];
}
return {flow, cost};
}
}
signed main() {
int m;
cin >> mcmf::n >> m; mcmf::S = 1, mcmf::T = n;
for (int i = 1, u, v, f, c; i <= m; i++) {
cin >> u >> v >> f >> c;
mcmf::add(u, v, f, c);
}
auto [flow, cost] = mcmf::flow();
cout << flow << " " << cost << "\n";
return 0;
}
Details
answer.code: In function ‘void mcmf::spfa()’: answer.code:31:30: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 31 | auto [v, f, c] = el[i]; | ^ answer.code: In function ‘bool mcmf::dij()’: answer.code:53:30: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 53 | auto [v, f, c] = el[i]; | ^ answer.code:66:36: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 66 | const auto [v, f, c] = el[i]; | ^ answer.code: In function ‘long long int mcmf::dinic(long long int, long long int)’: answer.code:81:23: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 81 | auto &[v, f, c] = el[e[u][i]]; | ^ answer.code: In function ‘int main()’: answer.code:109:55: error: ‘n’ was not declared in this scope; did you mean ‘mcmf::n’? 109 | cin >> mcmf::n >> m; mcmf::S = 1, mcmf::T = n; | ^ | mcmf::n answer.code:6:5: note: ‘mcmf::n’ declared here 6 | int n, S, T; | ^ answer.code:114:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 114 | auto [flow, cost] = mcmf::flow(); | ^