一道小题
2024-07-12 15:57:48
发布于:上海
#include <iostream>
#include <vector>
using namespace std;
vector<int> G[20005];
int n, m;
int a, b;
bool u = false;
bool vis[20005];
void dfs(int d);
int main() {
cin >> n >> m >> a >> b;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
G[x].push_back(y);
}
dfs(a);
if (u)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
void dfs(int d) {
if (vis[d]) {
return;
}
if (d == b) {
u = true;
return;
}
vis[d] = true;
cout << d << endl;
for (int t : G[d])
dfs(t);
return ;
}
这里空空如也
有帮助,赞一个