A Graceful Graph is a type of Simple Graph. Graceful graphs are special because there is a way to label all their nodes with positive integers so that when the edges are also labeled with the differences of the nodes they connect, no two edges have the same label and every label up to the number of edges is used.
Worked Out Example
Here is a Simple graph that we suspect is a Graceful graph
Let us try the following labeling:
Note we are permitted to skip integers in our node labeling. Now we label every edge with the positive difference between the nodes it connects. For increased visibility I have labeled these in red.
Each edge has a unique number and no number between between 1 and 7 (the number of edges we have) is left out. Thus our graph is graceful.
Task
Given a graph, via any reasonable method of input, output a truthy value if it is graceful and a falsy value otherwise.
This is code-golf so the objective is to minimize your byte count.
Test Cases
Here graphs are represented as an array of edges:
3 nodes:
[(0,1),(0,2),(1,2)]
True
Labeling:
Node 0 -> 0
Node 1 -> 2
Node 2 -> 3
5 nodes:
[(0,1),(0,4),(1,2),(2,3),(3,4)]
False
5 nodes:
[(0,1),(1,2),(2,3),(3,4)]
True
Labeling:
Node 0 -> 0
Node 1 -> 1
Node 2 -> 3
Node 3 -> 6
Node 4 -> 10
9 nodes
[(0,1),(1,2),(1,7),(1,8),(2,3),(2,6),(3,4),(4,5)]
True
Labeling:
Node 0 -> 0
Node 1 -> 1
Node 2 -> 3
Node 3 -> 6
Node 4 -> 10
Node 5 -> 15
Node 6 -> 11
Node 7 -> 7
Node 8 -> 8
5 nodes
[(0,1),(0,2),(1,2),(1,3),(1,4),(3,4)]
False
[(0,1),(1,2),(2,3),(3,4)]
is probably a noteworthy edge case. \$\endgroup\${(k-1,k) : 0 < k < n}
require the highest labels of all graphs with the same number of nodes. \$\endgroup\$n(n+1)/2
as their highest label. I have added your test case. \$\endgroup\$