Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void f1(int a[100][100], int n)
  6. {
  7.     int i, j;
  8.     for (i = 1; i <= n; i++)
  9.     {
  10.         cout << i << ": ";
  11.         for (j = 1; j <= n; j++)
  12.             if (a[i][j] == 1)
  13.                 cout << j << " ";
  14.         cout << endl;
  15.     }
  16. }
  17.  
  18. int f2(int a[100][100], int n, v[100])
  19. {
  20.     int i, j, ok = 0, pi, pf;
  21.     // for (i = 1; i <= n; i++)
  22.     //     for (j = 1; j <= n; j++)
  23.     //         if (a[i][j] == 1)
  24.     for (i = 2; i <= n; i++)
  25.         if (a[v[i]][v[i - 1]] == 0)
  26.         {
  27.             if (ok == 0)
  28.             {
  29.                 pi = i;
  30.                 pf = n;
  31.             }
  32.             ok++;
  33.         }
  34.     if (ok == 0)
  35.     {
  36.         for (i = 1; i <= n; i++)
  37.             if (v[i] != v[n])
  38.                 return 0;
  39.         return 1;
  40.     }
  41.     else
  42.         return 0;
  43. }
  44.  
  45. int a[100][100];
  46.  
  47. int main()
  48. {
  49.     int n, i, m, x, y;
  50.     cin >> n >> m;
  51.     for (i = 1; i <= m; i++)
  52.     {
  53.         cin >> x >> y;
  54.         a[x][y] = a[y][x] = 1;
  55.     }
  56.     f2(a, n);
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement