文章
10
粉丝
224
获赞
12
访问
51.0k
思路:广度优先搜索。队列记录路径节点,奇数点+1,偶数点+2,走到goal时结束搜索。
#include <bits/stdc++.h>
using namespace std;
typedef struct node
{
int num;
int sum;
node() {}
node(int num, int sum)
{
this->num = num;
this->sum = sum;
}
} node;
int main()
{
int n, m, s, goal, limit;
while (scanf("%d %d %d %d %d", &n, &m, &s, &goal, &limit) != EOF)
{
// n个点 m条路 起点s 终点t 时限limit
vector<vector<int>> g(n + 1, vector<int>(n + 1, 1e5));
for (int i = 0; i < m; i++)
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (g[a][b] > c)
g[a][b] = g[b][a] = c;
}
int res = 0;
int state = 0;
queue<node> queue;
vector<bool> vis(n + 1, false);
queue.push(node(s, 0));
while (!queue.empty())
{
node t = queue.f...
登录后发布评论
暂无评论,来抢沙发