谜之 RE
  • 板块学术版
  • 楼主Disjoint_cat
  • 当前回复9
  • 已保存回复9
  • 发布时间2023/7/19 14:08
  • 上次更新2023/11/3 08:54:44
查看原帖
谜之 RE
549499
Disjoint_cat楼主2023/7/19 14:08

正在写 Dinic 网络流模板。

这个代码本地能过样例。

然后我把 bfs 函数里的 cerr<<"bfs()\n"; 这一句注释掉了,然后再跑样例。

他 RE 掉了

求原因,为何一句调试语句删掉了就 RE 了

#include<bits/stdc++.h>
#define ll long long
#define endl '\n'//交互题删掉
#define FastIO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define FileIO(Name) freopen(Name ".in","r",stdin);\
freopen(Name ".out","w",stdout)
#define Fix(Dec) cout<<fixed<<setprecision(Dec)
#define sp_el(i,n) " \n"[i==n]
#define put_ret(Msg) return cout<<Msg<<endl,void()
#define nonEmp(x) !x.empty()
#define PB emplace_back
#define PPB pop_back
#define MP make_pair
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define VI vector<int>
#define VL vector<ll>
using namespace std;

void Init()
{
	FastIO;
}
const int N=205;
int n,m,S,T;
struct E
{
	int v;
	ll cap;
	E *rev;
	E(int v,int cap=0,E *rev=NULL):v(v),cap(cap),rev(rev){}
};
vector<E>g[N];
int dep[N],nxt[N];

bool bfs()
{
	cerr<<"bfs()\n";
	queue<int>q;
	q.push(S);
	memset(dep,-1,sizeof(dep));
	dep[S]=0;
	while(nonEmp(q))
	{
		int x=q.front();q.pop();
		for(E e:g[x])
			if(e.cap&&!~dep[e.v])
				dep[e.v]=dep[x]+1,q.push(e.v);
	}
//	cerr<<"dep=[";
//	for(int i=1;i<=n;i++)cerr<<dep[i]<<",]"[i==n];
//	cerr<<"\n";
	return ~dep[T];
}
vector<E*>edges;
ll dfs(int x)
{
//	cerr<<"dfs("<<x<<")\n";
	if(x==T)return LLONG_MAX;
	for(;nxt[x]<g[x].size();nxt[x]++)
	{
		E &e=g[x][nxt[x]];
		if(!e.cap||dep[e.v]<=dep[x])continue;
		edges.PB(&e);
		ll f=dfs(e.v);
		if(f)return min(f,e.cap);
		edges.PPB();
	}
	return 0;
}
ll dinic()
{
	ll maxflow=0;
	while(bfs())
	{
		memset(nxt,0,sizeof(nxt));
		ll flow;
		while(1)
		{
			flow=dfs(S);
			if(!flow)break;
//			cerr<<"flow "<<flow<<endl;
			maxflow+=flow;
			for(E *e:edges)
			{
				e->cap-=flow;
				e->rev->cap+=flow;
			}
			edges.clear();
		}
	}
	return maxflow;
}
void Solve()
{
	cin>>n>>m>>S>>T;
	for(int i=1;i<=m;i++)
	{
		int x,y,z;
		cin>>x>>y>>z;
		g[x].PB(E(y,z));
		g[y].PB(E(x));
		g[x].back().rev=&g[y].back();
		g[y].back().rev=&g[x].back();
	}
	cout<<dinic();
}
void QingKong()
{

}

int main()
{
#ifdef LOCAL
ll STE=clock();
#endif
	Init();
	int T=1;
	//cin>>T;
	while(T--)
	{
		Solve();
		QingKong();//多测不清空,抱灵两行泪
	}
#ifdef LOCAL
ll ETE=clock();
cerr<<"\n\n-----------------------\nProgram done in "<<ETE-STE<<" ms";
#endif
	return 0;
}
2023/7/19 14:08
加载中...