其实就是求最短路径问题,采用BFS即可。
AC代码如下:
#include <iostream>
#include <queue>
using namespace std;
const int maxn=2e5+5;
bool vis[maxn];
struct cow{
int pos;
int step;
cow(int xx,int s):pos(xx),step(s){
};
};
void bfs(int n,
其实就是求最短路径问题,采用BFS即可。
AC代码如下:
#include <iostream>
#include <queue>
using namespace std;
const int maxn=2e5+5;
bool vis[maxn];
struct cow{
int pos;
int step;
cow(int xx,int s):pos(xx),step(s){
};
};
void bfs(int n,