python.graphs

By Vitaly Pavlenko, ago, written in Python.
URL http://pastecode.org/index.php/view/97735491
Download Paste or View RawExpand paste to full width of browser | Change Viewing Options
  1. n, m = map(int, input().split())
  2. a = [[0 for i in range(n)] for j in range(n)]
  3.  
  4. for i in range(m):
  5.         u, v = map(int, input().split())
  6.         u -= 1
  7.         v -= 1
  8.         a[u][v] = 1
  9.         a[v][u] = 1
  10.  
  11. res = True
  12. for i in range(n):
  13.         for j in range(i + 1, n):
  14.                 for k in range(n):
  15.                         if (i != k) and (j != k) and (a[i][j] == 1) and (a[j][k] == 1) and (a[i][k] == 0):
  16.                                 res = False
  17.  
  18. if res:
  19.         print('YES')
  20. else:
  21.         print('NO')

Here you can reply to the paste above

Make Private

   

Feeling clever? Set some advanced options.