Advertisement
welleyth

3988. Transitivity of a graph

Dec 26th, 2020
1,223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6. #define mp make_pair
  7. #define pb push_back
  8.  
  9. const int N = 101;
  10.  
  11. int g[N][N];
  12.  
  13. signed main()
  14. {
  15.     ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
  16.     //freopen("input.txt","r",stdin);
  17.     //freopen("output.txt","w",stdout);
  18.  
  19.     int n,m;
  20.     cin >> n >> m;
  21.  
  22.     int a,b;
  23.  
  24.     for(int i=0;i<m;i++)
  25.     {
  26.         cin >> a >> b;
  27.         g[a][b]=1;
  28.         g[b][a]=1;
  29.     }
  30.  
  31.     for(int i=1;i<=n;i++)
  32.     {
  33.         for(int j=i+1;j<=n;j++)
  34.         {
  35.             for(int k=j+1;k<=n;k++)
  36.             {
  37.                 if((g[i][j] && g[j][k] && !g[k][i])
  38.                 || (g[i][j] && !g[j][k] && g[k][i])
  39.                 || (!g[i][j] && g[j][k] && g[k][i]))
  40.                 {
  41.                     cout << "NO";
  42.                     return 0;
  43.                 }
  44.             }
  45.         }
  46.     }
  47.  
  48.     cout << "YES";
  49.  
  50.     return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement