Advertisement
STANAANDREY

find cycle

Jan 26th, 2021 (edited)
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int n, m, a[101][101], vis[101], ok;
  4.  
  5. void dfs(int i) {
  6.     vis[i] = 1;
  7.     for (int j = 1; j <= n; j++)
  8.         if (a[i][j]) {
  9.             a[i][j] = a[j][i] = 0;
  10.             if (vis[j])
  11.                 ok = 1;
  12.             else
  13.                 dfs(j);
  14.         }
  15. }
  16.  
  17. int main() {
  18.     cin >> n >> m;
  19.     int x, y;
  20.     for (int i = 1; i <= m; i++) {
  21.         cin >> x >> y;
  22.         a[x][y] = a[y][x] = 1;
  23.     }
  24.     dfs(1);
  25.     if (ok)
  26.         cout << "DA";
  27.     else
  28.         cout << "NU";
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement