n = int(input()) platforms = [] platforms_indexes = [0 for x in range(0, n)] for i in range(0, n): links = [int(x)-1 for x in input().split()] platforms.append(links[1:]) def get_route(): #route = "0" index = 0 while len(platforms[index]) > 0: #route = route + ":" + str(platforms[index][platforms_indexes[index]]) new_index = platforms[index][platforms_indexes[index]] if platforms_indexes[index] == len(platforms[index]) - 1: platforms_indexes[index] = 0 else: platforms_indexes[index] += 1 index = new_index #print(route) #return route get_route() routes = 1 while all(item == 0 for item in platforms_indexes) == False: get_route() routes += 1 print(routes)
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 | n = int(input()) platforms = [] platforms_indexes = [0 for x in range(0, n)] for i in range(0, n): links = [int(x)-1 for x in input().split()] platforms.append(links[1:]) def get_route(): #route = "0" index = 0 while len(platforms[index]) > 0: #route = route + ":" + str(platforms[index][platforms_indexes[index]]) new_index = platforms[index][platforms_indexes[index]] if platforms_indexes[index] == len(platforms[index]) - 1: platforms_indexes[index] = 0 else: platforms_indexes[index] += 1 index = new_index #print(route) #return route get_route() routes = 1 while all(item == 0 for item in platforms_indexes) == False: get_route() routes += 1 print(routes) |