結果
問題 | No.19 ステージの選択 |
ユーザー | 👑 rin204 |
提出日時 | 2022-07-10 18:09:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 41 ms / 5,000 ms |
コード長 | 2,058 bytes |
コンパイル時間 | 265 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 53,248 KB |
最終ジャッジ日時 | 2024-06-11 08:10:25 |
合計ジャッジ時間 | 2,008 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
52,224 KB |
testcase_01 | AC | 35 ms
52,352 KB |
testcase_02 | AC | 35 ms
52,096 KB |
testcase_03 | AC | 35 ms
52,352 KB |
testcase_04 | AC | 37 ms
52,608 KB |
testcase_05 | AC | 35 ms
52,736 KB |
testcase_06 | AC | 38 ms
52,480 KB |
testcase_07 | AC | 38 ms
52,992 KB |
testcase_08 | AC | 41 ms
52,864 KB |
testcase_09 | AC | 39 ms
53,248 KB |
testcase_10 | AC | 40 ms
52,352 KB |
testcase_11 | AC | 36 ms
52,480 KB |
testcase_12 | AC | 35 ms
52,096 KB |
testcase_13 | AC | 36 ms
52,352 KB |
testcase_14 | AC | 36 ms
52,352 KB |
testcase_15 | AC | 36 ms
52,352 KB |
testcase_16 | AC | 36 ms
52,608 KB |
testcase_17 | AC | 36 ms
52,352 KB |
testcase_18 | AC | 37 ms
52,864 KB |
testcase_19 | AC | 36 ms
52,352 KB |
testcase_20 | AC | 35 ms
52,224 KB |
testcase_21 | AC | 36 ms
52,480 KB |
testcase_22 | AC | 36 ms
52,224 KB |
testcase_23 | AC | 36 ms
53,120 KB |
ソースコード
def scc(N, G): order = [] used = [False]*N group = [None]*N RG = [[] for _ in range(N)] for i in range(N): for j in G[i]: RG[j].append(i) def dfs(pos): stack = [(1, pos), (0, pos)] while stack: t, pos = stack.pop() if t == 0: if used[pos]: stack.pop() continue used[pos] = True for npos in G[pos]: if not used[npos]: stack.append((1, npos)) stack.append((0, npos)) else: order.append(pos) def rdfs(pos, col): stack = [pos] group[pos] = col used[pos] = True while stack: pos = stack.pop() for npos in RG[pos]: if not used[npos]: used[npos] = True group[npos] = col stack.append(npos) for i in range(N): if not used[i]: dfs(i) used = [False]*N label = 0 for s in reversed(order): if not used[s]: rdfs(s, label) label += 1 return label, group def construct(N, G, label, group): G0 = [[] for _ in range(label)] GP = [[] for _ in range(label)] for v in range(N): lbs = group[v] for w in G[v]: lbt = group[w] if lbs == lbt: continue G0[lbs].append(lbt) GP[lbs].append(v) return G0, GP n = int(input()) edges = [[] for _ in range(n)] L = [] for i in range(n): l, s = map(int, input().split()) s -= 1 L.append(l) edges[s].append(i) label, group = scc(n, edges) g0, gp = construct(n, edges, label, group) in_ = [0] * label for i in range(label): for j in g0[i]: in_[j] += 1 ans = sum(L) for i in range(label): if in_[i] == 0: mi = 1 << 30 for p in gp[i]: mi = min(mi, L[p]) ans += mi print(ans / 2)