Advertisement
mickypinata

PROG-T1057: Include

Dec 5th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. enum status{
  5.     uncheck = 0,
  6.     checking = 1,
  7.     checked = 2,
  8. };
  9.  
  10. const int N = 1000;
  11.  
  12. vector<int> adj[N + 1];
  13. vector<status> visited;
  14. int nVertex;
  15.  
  16. bool DFS(int u){
  17.     visited[u] = checking;
  18.     for(int v : adj[u]){
  19.         if(visited[v] != uncheck || !DFS(v)){
  20.             return false;
  21.         }
  22.     }
  23.     visited[u] = checked;
  24.     return true;
  25. }
  26.  
  27. int main(){
  28.  
  29.     scanf("%d", &nVertex);
  30.     for(int u = 1; u <= nVertex; ++u){
  31.         int nEdge;
  32.         scanf("%d", &nEdge);
  33.         for(int j = 1; j <= nEdge; ++j){
  34.             int v;
  35.             scanf("%d", &v);
  36.             adj[u].push_back(v);
  37.         }
  38.     }
  39.  
  40.     for(int u = 1; u <= nVertex; ++u){
  41.         visited.assign(nVertex + 1, uncheck);
  42.         if(DFS(u)){
  43.             cout << "NO\n";
  44.         } else {
  45.             cout << "YES\n";
  46.         }
  47.     }
  48.  
  49.     return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement