关于 Dinic 模板的某个问题
  • 板块学术版
  • 楼主xyz105
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/8/2 10:14
  • 上次更新2024/8/2 11:23:12
查看原帖
关于 Dinic 模板的某个问题
223100
xyz105楼主2024/8/2 10:14

已知 Dinic 中分层图的代码可能如下:

bool bfs()
{
	memset(dist, -1, sizeof(int) * (t + 5)), dist[s] = 0;
	if (s == t) return 1;
	deque<int> qu; qu.push_back(s);
	
	int u;
	while (qu.size())
	{
		u = qu.front(), qu.pop_front();
		cur[u] = head[u];
		for (int i = head[u]; i; i = nxt[i])
			if (w[i] && dist[to[i]] == -1)
			{
				dist[to[i]] = dist[u] + 1, qu.push_back(to[i]);
				if (to[i] == t) return 1;
			}
	}
	return dist[t] != -1;
}

其中 if (to[i] == t) return 1; 这句导致了 TLE,而删掉后能过。

有大佬教一下为啥这会被卡掉吗?

2024/8/2 10:14
加载中...