Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. vector < vector < int >> land;
  7.  
  8. int was[1010];
  9.  
  10. void dfs(int vp) {
  11.     was[vp] = 1;
  12.     for (int i = 0; i < (int)land[vp].size(); i++) {
  13.         if (was[land[vp][i]] == 0)
  14.             dfs(land[vp][i]);
  15.     }  
  16. }
  17.  
  18. int main() {
  19.     ios_base::sync_with_stdio(0);
  20.     cin.tie(0);
  21.     int N, M, V, U, K, a, b;
  22.     cin >> N >> M >> V >> U;
  23.     land.resize(N);
  24.    
  25.     for (int i = 0; i < M; i++) {
  26.         cin >> a >> b;
  27.         --a;
  28.         --b;
  29.         land[a].push_back(b);
  30.     }
  31.     cin >> K;
  32.     int bylk;
  33.     for (int i = 0; i < K; i++) {
  34.         cin >> bylk;
  35.         land[bylk - 1].clear();
  36.     }
  37.     dfs(V - 1);
  38.     if (was[U - 1])
  39.         cout << "YES";
  40.     else cout << "NO";
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement