Exemple #1
0
def main():
    n = int(cmdlinearg("n"))
    m = int(cmdlinearg("m"))
    k = int(cmdlinearg("k")) - 1
    edges = []
    for i in range(1, n):
        if i % 2 == 1:
            edges.append((i, i - 1))
        else:
            edges.append((i, i - 2))
    print_tree(n, m, k, edges)
def main():
    n = int(cmdlinearg("n"))
    m = n - 1
    k = n - 1
    edges = []
    for i in range(0, n - 2):
        edges.append((i, i + 1))
    edges.append((n // 2 - 1, n - 1))
    print_tree(n, m, k, edges)
Exemple #3
0
def main():
    n = int(cmdlinearg("n"))
    m = int(cmdlinearg("m"))
    width = int(cmdlinearg("width", 10**5))
    leaf = int(cmdlinearg("leaf", 0))
    nonleaf = int(cmdlinearg("nonleaf", 0))

    nodes = list(range(0, n))
    random.shuffle(nodes)
    parent = [-1] * n
    degree = [0] * n
    for i in range(1, n):
        j = random.randint(max(0, i - width), i - 1)
        parent[nodes[i]] = nodes[j]
        degree[nodes[i]] += 1
        degree[nodes[j]] += 1

    leaves = []
    nonleaves = []
    for i in range(0, n):
        if degree[i] == 1:
            leaves.append(i)
        else:
            nonleaves.append(i)

    k = random.randrange(n)
    if leaf == 1:
        k = random.choice(leaves)
    if nonleaf == 1 and nonleaves:
        k = random.choice(nonleaves)

    eds = []
    for i in nodes[1:n]:
        eds.append((i, parent[i]))

    print_tree(n, m, k, eds)
Exemple #4
0
def main():
    n = int(cmdlinearg("n"))
    m = int(cmdlinearg("m"))
    k = int(cmdlinearg("k")) - 1
    print_tree(n, m, k, [(0,i) for i in range(1, n)])
def main():
    n = int(cmdlinearg("n"))
    m = int(cmdlinearg("m"))
    k = int(cmdlinearg("k")) - 1
    print_tree(n, m, k, [(i, i+1) for i in range(n-1)], shuffle_nodes=False)