1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <bits/stdc++.h> #define ios ios::sync_with_stdio(0),cin.tie(0) #define lld long long #define N 1000 using namespace std; int n,m; bool visit[N]; vector<int>edge[N];
void dfs(int cur){ visit[cur] = 1; for(auto i:edge[cur]){ if(visit[i])continue; dfs(i); } }
void solve(){ memset(visit,0,sizeof(visit)); for(int i=0;i<=n+100;i++)edge[i].clear(); for(int i=0;i<m;i++){ int x,y;cin>>x>>y; edge[x].push_back(y); } int from,to;cin>>from>>to; dfs(from); if(visit[to])cout<<"Yes"<<endl; else cout<<"No"<<endl; }
signed main(){ while(cin>>n>>m){ solve(); } }
|