摘要:
题意:第 i 个火车站都有一个数字 Ki (0≤Ki ≤N),火车在第 i 站只能前进Ki 站或后退 Ki 站。火车只能在第 1 站和第 N 站之间行驶。 请问,从第 a 站到第 b 站最少需前进或后退多少次? 分析:利用BFS,将每个站出发能到的所有站都入队,不断更新下去,直到所有站都被到达或者车 阅读全文
摘要:
题意:无向连通图中,每条边距离为 1,问其中距离起点距离大于 d 的点数。 分析:由起点出发,标记每个点距离起点的距离。 #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1e5 + 1 阅读全文
摘要:
题意:求某点所在连通块的大小。 分析:由某点进行dfs,每次标记该点,并计数。 #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 110, INF = 0x3f3f3f3f; strin 阅读全文
摘要:
题意:求连通块的数量。 分析:遍历每个点,dfs处理没有标记过的连通点,每次标记完成都是一个连通块处理完成。 #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 110, INF = 0x 阅读全文