human
A subway scheme, classic for all Berland cities is represented by a set of n stations connected by n passages, each of which connects exactly two stations and does not pass through any others. Besides, in the classic scheme one can get from any station to any other one along the passages. The passages can be used to move in both directions. Between each pair of stations there is no more than one passage.

Berland mathematicians have recently proved a theorem that states that any classic scheme has a ringroad. There can be only one ringroad. In other words, in any classic scheme one can find the only scheme consisting of stations (where any two neighbouring ones are linked by a passage) and this cycle doesn't contain any station more than once.

This invention had a powerful social impact as now the stations could be compared according to their distance from the ringroad. For example, a citizen could say "I live in three passages from the ringroad" and another one could reply "you loser, I live in one passage from the ringroad". The Internet soon got filled with applications that promised to count the distance from the station to the ringroad (send a text message to a short number...).

The Berland government decided to put an end to these disturbances and start to control the situation. You are requested to write a program that can determine the remoteness from the ringroad for each station by the city subway scheme.

Input

The first line contains an integer n (3 ≤ n ≤ 3000), n is the number of stations (and trains at the same time) in the subway scheme. Then n lines contain descriptions of the trains, one per line. Each line contains a pair of integers xi, yi (1 ≤ xi, yi ≤ n) and represents the presence of a passage from station xi to station yi. The stations are numbered from 1 to n in an arbitrary order. It is guaranteed that xi ≠ yi and that no pair of stations contain more than one passage. The passages can be used to travel both ways. It is guaranteed that the given description represents a classic...
Using python3 can you solve the prior task?

=====
Give me a Python code to find the only scheme consisting of stations (where any two neighbouring ones are linked by a passage) and this cycle doesn't contain any station more than once?
assistant
#Here is Python code to find the only scheme consisting of stations (where any two neighbouring ones are linked by a passage) and this cycle doesn't contain any station more than once.

from collections import deque
import sys
sys.setrecursionlimit(5000)

class Graph(object):
    def __init__(self, vertices, adj):
        self.vertices = vertices#[v for v in range(1, vertices+1)]
        self.dist = self.init_dist(vertices)
        self.adj = adj
        
    def init_dist(self, v):
        d = {}
        for i in range(1, v+1):
            d[i] = 0
        return d
        
    # ~ def get_all_vertices(self):
        # ~ return self.vertices
        
    def iter_vertices(self):
        for v in range(1,self.vertices+1):
            yield v
        
    def adj_list(self, v):
        return self.adj[v]

		
class dfs_result:
    def __init__(self):
        self.dist = {}
        self.parent = {}
        self.finish_time = {}
        self.start_time = {}
        self.edges = {}
        self.order = []
        self.t = 0
        self.loop = None
        
        
        
def dfs(g):
    result = dfs_result()
    for vertex in g.iter_vertices():
        if vertex not in result.parent:
            dfs_visit(g, vertex, result )
    return result
			
def dfs_visit(g, v, result, parent = None):
    result.parent[v] = parent
    result.t  += 1
    result.start_time[v] = result.t
    if parent:
        result.edges[(parent, v)] = 'tree'

    for n in g.adj_list(v):
        if n not in result.parent:
            dfs_visit(g, n, result, v)
        elif (n not in result.finish_time):
            if (n,v) not in result.edges:
                result.edges[(v, n)] = 'back'
                result.loop = [v, n]
        elif result.start_time[v] < result.finish_time[n]:
            result.edges[(v, n)] = 'forward'
        else:
            result.edges[(v, n)] = 'cross'
    result.t += 1
    result.finish_time[v] = result.t
    result.order.append(v)
 
class BFSResult:
    def __init__(self):
        self.level = {}
        self.parent = {}
    
def bfs(g, r, loop_dict, s):
    r.parent = {s:None}
    r.level = {s:0}	

    queue = deque()
    queue.append(s)
    while queue:
        u = queue.popleft()
     ...