Help to find my bugs!!!

本文详细介绍了一种基于SPFA算法的最小费用最大流求解方法。通过C++代码实现,该算法在网络流问题中寻找从源点到汇点的最大流量路径,同时使得总费用最小。文章展示了完整的代码结构,包括数据结构定义、输入处理、增广路径搜索及主函数调用流程。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int inf = 987654321;
struct edge
{
    int flow;
    int cost;
    int to;
}E[200005];
queue <int> Q;
int cnt[200005];
int vis[200005];
int per[200005];
int dis[200005];
int fir[200005];
int nxt[200005];
int n, m, e;
int maxFlow,minCost;
bool SPFA(int s,int t)
{
    for(int i = 1; i <= n; i++)
    {
        dis[i] = inf;
        vis[i] = 0;
        per[i] = -1;
        cnt[i] = 0;
   }
   dis[s] = 0;
   vis[s] = 1;
   cnt[s]++;
   while(!Q.empty())
   {
       Q.pop();
   }
   Q.push(s);
   while(!Q.empty())
   {
       int p = Q.front();
       Q.pop();
       vis[p] = 0;
       for(int i = fir[p]; i != -1; i = nxt[i])
       {
           if(E[i].flow > 0 && dis[E[i].to] > dis[p] + E[i].cost)
           {
               dis[E[i].to] = dis[p] + E[i].cost;
               per[E[i].to] = i;
               if(!vis[E[i].to])
               {
                   Q.push(E[i].to);
                   vis[E[i].to] = 1;
                   if(++cnt[E[i].to] > n)
                   return false;
               }
           }
       }
   }
   if(dis[t] == inf)
   return false;
   else return true;
}
void addedge(int a,int b,int c,int d)
{
    e++;
    E[e].flow = c;
    E[e].cost = d;
    E[e].to = b;
    nxt[e] = fir[a];
    fir[a] = e;
    e++;
    E[e].flow = 0;
    E[e].cost = -c;
    E[e].to = a;
    nxt[e] = fir[b];
    fir[b] = e;
}
void input()
{
    memset(fir,-1,sizeof(fir));
    memset(nxt,-1,sizeof(nxt));
    scanf("%d %d", &n, &m);
    int a,b,c,d;
    for(int i = 0; i < m; i++)
    {
        scanf("%d %d %d %d", &a, &b, &c, &d);
        addedge(a,b,c,d);
    }
}
int solve()
{
    while(SPFA(1,n))
    {
        int thisflow = inf;
        int thiscost = 0;
        for(int i = per[n]; i != -1; i = per[E[i^1].to])
        {
            thisflow = min(thisflow,E[i].flow);
            thiscost += E[i].cost;
        }
        cout<<endl;
        for(int i = per[n]; i != -1; i = per[E[i^1].to])
        {
            E[i].flow += thisflow;
            E[i^1].flow -= thisflow;
        }
        maxFlow += thisflow;
        minCost += thiscost * thisflow;
    }
}
int main()
{
    input();
    solve();
    printf("%d %d",minCost, maxFlow);
    return 0;
}

2025-10-28T21:51:25.143820+08:00 61 [ERROR] InnoDB: Operating system error number 32 in a file operation. 2025-10-28T21:51:25.144814+08:00 61 [ERROR] InnoDB: The error means that another program is using InnoDB's files. This might be a backup or antivirus software or another instance of MySQL. Please close it to get rid of this error. 2025-10-28 21:51:35 0x4e50 InnoDB: Assertion failure in thread 20048 in file handler0alter.cc line 7404 InnoDB: Failing assertion: error == DB_SUCCESS 2025-10-28T21:51:35.146746+08:00 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 9706ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.) InnoDB: We intentionally generate a memory trap. InnoDB: Submit a detailed bug report to http://bugs.mysql.com. InnoDB: If you get repeated assertion failures or crashes, even InnoDB: immediately after the mysqld startup, there may be InnoDB: corruption in the InnoDB tablespace. Please refer to InnoDB: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html InnoDB: about forcing recovery. 13:51:35 UTC - mysqld got exception 0x80000003 ; This could be because you hit a bug. It is also possible that this binary or one of the libraries it was linked against is corrupt, improperly built, or misconfigured. This error can also be caused by malfunctioning hardware. Attempting to collect some information that could help diagnose the problem. As this is a crash and something is definitely wrong, the information collection process might fail. key_buffer_size=536870912 read_buffer_size=131072 max_used_connections=52 max_threads=600 thread_count=52 connection_count=52 It is possible that mysqld could use up to key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 761977 K bytes of memory Hope that's ok; if not, decrease some variables in the equation. Thread pointer: 0x168dca9d300 Attempting backtrace. You can use the following information to find out where mysqld died. If you see no messages after this, something went terribly wrong... 7ff657099812 mysqld.exe!my_sigabrt_handler()[my_thr_init.c:449] 7ff65743e349 mysqld.exe!raise()[winsig.c:587] 7ff65743d240 mysqld.exe!abort()[abort.c:82] 7ff657199b08 mysqld.exe!ut_dbg_assertion_failed()[ut0dbg.cc:67] 7ff65727f72f mysqld.exe!ha_innobase::commit_inplace_alter_table()[handler0alter.cc:8275] 7ff656a11443 mysqld.exe!mysql_inplace_alter_table()[sql_table.cc:7449] 7ff656a0f17a mysqld.exe!mysql_alter_table()[sql_table.cc:9538] 7ff656b3565e mysqld.exe!Sql_cmd_alter_table::execute()[sql_alter.cc:316] 7ff656996aa5 mysqld.exe!mysql_execute_command()[sql_parse.cc:3521] 7ff65699938a mysqld.exe!mysql_parse()[sql_parse.cc:5525] 7ff65699239d mysqld.exe!dispatch_command()[sql_parse.cc:1432] 7ff6569933aa mysqld.exe!do_command()[sql_parse.cc:999] 7ff6569581e4 mysqld.exe!handle_connection()[connection_handler_per_thread.cc:301] 7ff65737cd92 mysqld.exe!pfs_spawn_thread()[pfs.cc:2191] 7ff65709967b mysqld.exe!win_thread_start()[my_thread.c:38] 7ff65743ddbf mysqld.exe!_callthreadstartex()[threadex.c:376] 7ff65743e00a mysqld.exe!_threadstartex()[threadex.c:354] 7ffaba1f84d4 KERNEL32.DLL!BaseThreadInitThunk() 7ffabc6ee871 ntdll.dll!RtlUserThreadStart() Trying to get some variables. Some pointers may be invalid and cause the dump to abort. Query (168df559740): ALTER TABLE formmain_0495 DROP COLUMN field0028 Connection ID (thread ID): 61 Status: NOT_KILLED The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains information that should help you find out what is causing the crash.
10-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值