SHARE
TWEET

Untitled

a guest Oct 18th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. vector <vector <int>> k;
  6. vector <int> put;
  7. int was[100001];
  8.  
  9.  
  10. void dfs(int u){
  11.     put.push_back(u);
  12.     was[u]=1;
  13.     if(k[u].empty()){
  14.         cout<<"NO";
  15.         exit(0);
  16.     }
  17.     else{
  18.         for(int i=0; i<(int)k[u].size(); i++){
  19.             if(was[k[u][i]]==1){
  20.                 cout<<"YES";
  21.                 int en=u;
  22.                 while(en!=k[u][i]){
  23.                    
  24.                 }
  25.             }
  26.             else{
  27.                 dfs(k[u][i]);
  28.             }
  29.         }
  30.     }
  31. }
  32.  
  33. int main(){
  34.     int v, r;
  35.     cin>>v>>r;
  36.     k.resize(v+1);
  37.     put.resize(v+1);
  38.     for(int i=0; i<r; i++){
  39.         int a, b;
  40.         cin>>a>>b;
  41.         k[a].push_back(b);
  42.     }
  43.     dfs(1);
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top