<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_cycle(filename, graph, cycle, directed):
 """Write an eulerian tour in DOT format :param filename: the file to be written in DOT format :param graph: graph in listlist format, cannot be listdict :param bool directed: describes the graph :param cycle: tour as a vertex list :returns: nothing :complexity: `O(|V|^2 + |E|)` """

    n = len(graph)
    weight = [[float('inf')] * n for _ in range(n)]
    for r in range(1, len(cycle)):
        weight[cycle[r-1]][cycle[r]] = r
        if not directed:
            weight[cycle[r]][cycle[r-1]] = r
    write_graph(filename, graph, arc_label=weight, directed=directed)