求救
一直wa一个点,麻烦大佬们帮我看下
#include <iostream>
#include <queue>
#include <vector>
#include <cstring>
using namespace std;
const int maxn = 1e4;
queue<int> q;
vector<int> G[maxn];
int step[maxn];
bool vis[maxn];
bool used[maxn];
int main(void)
{
ios::sync_with_stdio(false);
int n, m, s, t;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
G[y].push_back(x);
}
cin >> s >> t;
q.push(t);
while (q.size()) {
int u = q.front();
q.pop();
if (vis[u]) continue;
vis[u] = 1;
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
q.push(v);
}
}
memcpy(used, vis, sizeof(vis));
for (int i = 1; i <= n; i++) {
if (!vis[i]) {
for (int j = 0; j < G[i].size(); j++) {
int v = G[i][j];
used[v] = 0;
}
}
}
for (int i = 1; i <= n; i++) step[i] = -1;
step[t] = 0;
q.push(t);
while (q.size()) {
int u = q.front();
q.pop();
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (!used[v] || step[v] != -1) continue;
step[v] = step[u] + 1;
q.push(v);
}
}
cout << step[s] << endl;
return 0;
}