結果
問題 | No.19 ステージの選択 |
ユーザー | convexineq |
提出日時 | 2021-02-18 17:54:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 42 ms / 5,000 ms |
コード長 | 1,814 bytes |
コンパイル時間 | 274 ms |
コンパイル使用メモリ | 81,720 KB |
実行使用メモリ | 54,416 KB |
最終ジャッジ日時 | 2024-09-14 23:28:18 |
合計ジャッジ時間 | 2,090 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
53,188 KB |
testcase_01 | AC | 39 ms
52,500 KB |
testcase_02 | AC | 40 ms
54,072 KB |
testcase_03 | AC | 40 ms
53,716 KB |
testcase_04 | AC | 41 ms
53,188 KB |
testcase_05 | AC | 40 ms
52,736 KB |
testcase_06 | AC | 41 ms
54,416 KB |
testcase_07 | AC | 41 ms
53,540 KB |
testcase_08 | AC | 42 ms
52,692 KB |
testcase_09 | AC | 40 ms
53,212 KB |
testcase_10 | AC | 39 ms
53,440 KB |
testcase_11 | AC | 39 ms
53,756 KB |
testcase_12 | AC | 40 ms
53,724 KB |
testcase_13 | AC | 39 ms
52,940 KB |
testcase_14 | AC | 39 ms
53,164 KB |
testcase_15 | AC | 39 ms
53,132 KB |
testcase_16 | AC | 39 ms
53,296 KB |
testcase_17 | AC | 39 ms
52,852 KB |
testcase_18 | AC | 40 ms
52,696 KB |
testcase_19 | AC | 40 ms
53,016 KB |
testcase_20 | AC | 40 ms
53,884 KB |
testcase_21 | AC | 40 ms
52,212 KB |
testcase_22 | AC | 39 ms
52,764 KB |
testcase_23 | AC | 40 ms
53,236 KB |
ソースコード
def SCC_Tarjan(g): n = len(g) order = [-1]*n # 負なら未処理、[0,n) ならpre-order, n ならvisited low = [0]*n ord_now = 0 parent = [-1]*n gp = [0]*n gp_num = 0 S = [] q = [] for i in range(n): if order[i] == -1: q.append(i) while q: v = q.pop() if v >= 0: if order[v] != -1: continue order[v] = low[v] = ord_now ord_now += 1 S.append(v) q.append(~v) for c in g[v]: if order[c] == -1: q.append(c) parent[c] = v else: low[v] = min(low[v], order[c]) else: v = ~v if parent[v] != -1: low[parent[v]] = min(low[parent[v]], low[v]) if low[v] == order[v]: while True: w = S.pop() order[w] = n gp[w] = gp_num if w==v: break gp_num += 1 scc = [[] for _ in range(gp_num)] for i in range(n): gp[i] = gp_num-gp[i]-1 scc[gp[i]].append(i) return scc, gp, gp_num n = int(input()) g = [[] for _ in range(n)] diff = [0]*n for i in range(n): l,s = map(int,input().split()) g[s-1].append(i) diff[i] = l scc,gp,m = SCC_Tarjan(g) indegree = [0]*m for v in range(n): for c in g[v]: if gp[v] != gp[c]: indegree[gp[c]] = 1 ans = sum(diff) for i in range(m): if indegree[i] == 0: ans += min(diff[k] for k in scc[i]) print(ans/2)