-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzad1.py
More file actions
33 lines (25 loc) · 926 Bytes
/
zad1.py
File metadata and controls
33 lines (25 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from checker import chordal_checker
from lexBFS import lexBFS, Node, gen_nodes_list
def chordal_check(V, L):
G = gen_nodes_list(V, L)
G : list[Node]
order = lexBFS(G, V)
og_idx_to_order = [None] * (V + 1)
for i in range(V):
og_idx_to_order[order[i]] = i
RN = [set() for _ in range(V + 1)]
parent = [None] * (V + 1)
for i in range(1, V): # nie ma sensu sprawdzać pierwszego elementu order, bo wszystko puste
v = order[i]
last_idx = -1
for u in G[v].out:
u_idx = og_idx_to_order[u]
if u_idx < i:
RN[v].add(u)
if u_idx > last_idx:
last_idx = u_idx
parent[v] = order[last_idx] if last_idx != -1 else None
if parent[v] is not None and not (RN[v] - {parent[v]} <= RN[parent[v]]):
return False
return True
chordal_checker(chordal_check)