QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#671074#602. 最小费用最大流(随机数据)QingyyxCompile Error//C++203.7kb2024-10-24 10:39:552024-10-24 10:39:56

Judging History

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

  • [2024-10-24 10:39:56]
  • 评测
  • [2024-10-24 10:39:55]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
// #define int ll
#define enl putchar('\n')
#define all(x) (x).begin(),(x).end()
#define debug(x) printf(" "#x":%d\n",x);
using namespace std;
const int N = 400 + 5, M = 15000;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
typedef pair<int, int> pii;
char buf[1 << 21], * p1 = buf, * p2 = buf, obuf[1 << 21], * o = obuf, of[35];
#define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline ll qpow(ll a, ll n) { ll res = 1; while (n) { if (n & 1)res = res * a % mod; n >>= 1; a = a * a % mod; }return res; }
template <class T = int>inline T read() { T s = 0, f = 1; char c = gc(); for (; !isdigit(c); c = gc())if (c == '-')f = -1; for (; isdigit(c); c = gc())s = s * 10 + c - '0'; return s * f; }
inline void read(int* a, int n) { for (int i = 1; i <= n; ++i)a[i] = read(); }
inline int inal(char* s) { int n = 0; for (s[0] = gc(); !isalpha(s[0]); s[0] = gc()); for (; isalpha(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline int indi(char* s) { int n = 0; for (s[0] = gc(); !isdigit(s[0]); s[0] = gc()); for (; isdigit(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline void outd(auto* a, int n) { for (int i = 1; i <= n; ++i)printf("%d ", a[i]); enl; }
int n, m, S, T, totnode;

int head[N], tot, dis[N], cur[N], cst;
bool vis[N];
struct node {
    int to, nxt, val, ct;
}e[M << 1];
queue<int>que;
inline void add(int u, int v, int w, int c) {
    e[tot] = {v, head[u], w, c};
    head[u] = tot++;

    e[tot] = {u, head[v], 0, -c};
    head[v] = tot++;
}
inline bool spfa() {
    while (!que.empty())que.pop();
    memset(dis, 0x7f, sizeof(dis));
    memset(vis, 0, sizeof(vis));
    memcpy(cur, head, sizeof(head));
    // for (int i = 1; i <= n; ++i)cur[i] = head[i];
    dis[S] = 0;

    que.push(S);
    while (!que.empty()) {
        int t = que.front();
        que.pop();
        vis[t] = 0;
        for (int i = head[t]; ~i; i = e[i].nxt) {
            int to = e[i].to;
            if (dis[to] > dis[t] + e[i].ct && e[i].val) {
                dis[to] = dis[t] + e[i].ct;
                if (!vis[to]) {
                    vis[to] = 1;
                    que.push(to);
                }
            }
        }
    }
    if (dis[T] ^ dep[0])return true;
    else return false;
}
inline int dfs(int now, int lim) {
    if (!lim || now == T)return lim;
    int flow = 0, f;
    vis[now] = 1;
    for (int i = cur[now]; ~i; i = e[i].nxt) {
        cur[now] = i;
        if (!vis[e[i].to] && dis[e[i].to] == dis[now] + e[i].ct && (f = dfs(e[i].to, min(lim, e[i].val)))) {
            flow += f;
            cst += f * e[i].ct;
            lim -= f;
            e[i].val -= f;
            e[i ^ 1].val += f;
            if (!lim)break;
        }
    }
    vis[now] = 0;
    return flow;
}
inline int MCMF() {
    int ans = 0;
    while (spfa())
        ans += dfs(S, 0x7fffffff);
    return ans;
}
void solve() {
    n = read(), m = read(), S = 1, T = n;
    totnode = n;
    memset(head, -1, sizeof(head));
    for (int i = 1; i <= m; ++i) {
        int u = read(), v = read(), w = read(), c = read();
        add(u, v, w, c);
    }
    int ans = MCMF();
    printf("%d %d\n", ans, cst);
}
signed main(signed argc, char const* argv[]) {
    clock_t c1 = clock();
#ifdef LOCAL
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif
    //=============================================================
    int TxT = 1;
    // TxT = read();
    while (TxT--)
        solve();
    //=============================================================
#ifdef LOCAL
    end :
    cerr << "Time Used:" << clock() - c1 << "ms" << endl;
#endif
    return 0;
}

详细

answer.code: In function ‘bool spfa()’:
answer.code:60:18: error: ‘dep’ was not declared in this scope; did you mean ‘dup’?
   60 |     if (dis[T] ^ dep[0])return true;
      |                  ^~~
      |                  dup
answer.code:62:1: warning: control reaches end of non-void function [-Wreturn-type]
   62 | }
      | ^