QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#589966#602. 最小费用最大流(随机数据)TauLee01Compile Error//C++171.9kb2024-09-25 20:52:022024-09-25 20:52:02

Judging History

This is the latest submission verdict.

  • [2024-09-25 20:52:02]
  • Judged
  • [2024-09-25 20:52:02]
  • Submitted

answer

#include<bits/stdc++.h>
using namespcae std;

const int Maxn = 510, Maxm = 1e5 + 5;
const int INF = 0x3f3f3f3f;
struct node {
    int to, nex, w, c;
} eg[Maxm];
bool vis[Maxn];
int tot = 1, fee, cur[Maxn], dis[Maxn], head[Maxn];

void add(int u, int v, int w, int c) {
    eg[++tot].to = v;
    eg[tot].w = w;
    eg[tot].c = c;
    eg[tot].nex = head[u];
    head[u] = tot;
}

void addedge(int u, int v, int w, int c) { add(u, v, w, c), add(v, u, 0, -c); }

bool spfa(int s, int t) {
    memset(dis, 0x3f, sizeof(dis)); //初始距离为无穷
    memcpy(cur, head, sizeof(head)); //当前出初始化为head的第一个
    std::queue<int> q;
    q.push(s), dis[s] = 0, vis[s] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop(), vis[u] = 0;
        for (int i = head[u]; i; i = eg[i].nex) {
            int v = eg[i].to;
            if (eg[i].w && dis[v] > dis[u] + eg[i].c) {
                dis[v] = dis[u] + eg[i].c;
                if (!vis[v]) q.push(v), vis[v] = 1;
            }
        }
    }
    return dis[t] != INF;
}

int dfs(int u, int t, int flow) {
    if (u == t) return flow;
    vis[u] = 1;
    int ans = 0;
    for (int &i = cur[u]; i && ans < flow; i = eg[i].nex) {
        int v = eg[i].to;
        if (!vis[v] && eg[i].w && dis[v] == dis[u] + eg[i].c) {
            int x = dfs(v, t, std::min(eg[i].w, flow - ans));
            if (x) fee += x * eg[i].c, eg[i].w -= x, eg[i ^ 1].w += x, ans += x;
        }
    }
    vis[u] = 0;
    return ans;
}

int dinic(int s, int t) {
    int ans = 0;
    while (spfa(s, t)) {
        int x;
        while ((x = dfs(s, t, INF))) ans += x;
    }
    return ans;
}
signed main()
{
    int n;
    cin >> n;
int m;
cin>>m;
int u,v,w,c;
for(int i=1;i<=m;i++){
cin>>u>>v>>w>>c;
addedge(u,v,w,c);
}
    // 最小费用
    //addedge(i, j, w, c);

    int ans = dinic(s, t);
    debug(ans, fee);

cout<<ans<<" "<<fee<<endl;

}

詳細信息

answer.code:2:7: error: expected nested-name-specifier before ‘namespcae’
    2 | using namespcae std;
      |       ^~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:67:5: error: ‘cin’ was not declared in this scope; did you mean ‘std::cin’?
   67 |     cin >> n;
      |     ^~~
      |     std::cin
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:146,
                 from answer.code:1:
/usr/include/c++/13/iostream:62:18: note: ‘std::cin’ declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
answer.code:78:21: error: ‘s’ was not declared in this scope
   78 |     int ans = dinic(s, t);
      |                     ^
answer.code:78:24: error: ‘t’ was not declared in this scope
   78 |     int ans = dinic(s, t);
      |                        ^
answer.code:79:5: error: ‘debug’ was not declared in this scope
   79 |     debug(ans, fee);
      |     ^~~~~
answer.code:81:1: error: ‘cout’ was not declared in this scope; did you mean ‘std::cout’?
   81 | cout<<ans<<" "<<fee<<endl;
      | ^~~~
      | std::cout
/usr/include/c++/13/iostream:63:18: note: ‘std::cout’ declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
answer.code:81:22: error: ‘endl’ was not declared in this scope; did you mean ‘std::endl’?
   81 | cout<<ans<<" "<<fee<<endl;
      |                      ^~~~
      |                      std::endl
In file included from /usr/include/c++/13/istream:41,
                 from /usr/include/c++/13/sstream:40,
                 from /usr/include/c++/13/complex:45,
                 from /usr/include/c++/13/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127:
/usr/include/c++/13/ostream:735:5: note: ‘std::endl’ declared here
  735 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~