Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. def cluster_2(ver, eds, num_of_clusters, parent, n):
  2.     cnt = 1 # количество владельцев
  3.     while(cnt < num_of_clusters):
  4.         max_edg = 0
  5.         for i in range(len(eds)):
  6.             l = eds[i][0]
  7.             a = eds[i][1]
  8.             b = eds[i][2]
  9.             if a != parent[b]:
  10.                 a, b = b, a
  11.             if a == parent[b] and l >= max_edg:
  12.                 max_edg = l
  13.                 new_p = b
  14.         parent[new_p] = new_p
  15.         for i in range(len(eds)):
  16.             l = eds[i][0]
  17.             a = eds[i][1]
  18.             b = eds[i][2]
  19.             if a != parent[b]:
  20.                 a, b = b, a
  21.             if a == parent[b] and l < eds[int(n * min(b, new_p) - min(b, new_p) * (min(b, new_p) + 1) / 2 + (max(b, new_p) - min(b, new_p)) - 1)][0]:
  22.                 parent[b] = new_p
  23.         cnt += 1
  24.     return parent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement