제출 #1084753

#제출 시각아이디문제언어결과실행 시간메모리
1084753IzzyBosses (BOI16_bosses)Cpython 3
67 / 100
1557 ms3932 KiB
def test(start): visited = [False for i in range(n)] levels = [[start]] lvl = 0 pos = 0 salary = 0 visited[start] = True while lvl < len(levels): # print(levels, salary) start = levels[lvl][pos] if start in arr: for i in arr[start]: if not visited[i]: visited[i] = True if len(levels) > lvl + 1: levels[lvl + 1].append(i) else: levels.append([i]) pos += 1 if pos == len(levels[lvl]): salary += len(levels[lvl]) * (lvl + 1) lvl += 1 pos = 0 a = set(visited) if True in a and len(a) == 1: # print(levels) return salary return float('inf') salary = float('inf') n = int(input()) arr = {} for i in range(n): x = [int(i) - 1 for i in input().split(' ')[1:]] for j in x: if j in arr: arr[j].append(i) else: arr[j] = [i] for i in arr: salary = min(salary, test(i)) print(salary)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...