python.graphs

By Vitaly Pavlenko, ago, written in Python.
URL http://pastecode.org/index.php/view/71296221
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
  16.                 (a[j][k] == 1) and (a[i][k] == 0)):
  17.                 res = False
  18.  
  19. if res:
  20.     print('YES')
  21. else:
  22.     print('NO')

Here you can reply to the paste above

Make Private

   

Feeling clever? Set some advanced options.