結果
問題 | No.2464 To DAG |
ユーザー | fiblonaria |
提出日時 | 2023-09-21 19:08:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,665 ms / 2,000 ms |
コード長 | 1,205 bytes |
コンパイル時間 | 256 ms |
コンパイル使用メモリ | 87,032 KB |
実行使用メモリ | 311,004 KB |
最終ジャッジ日時 | 2023-09-21 19:09:28 |
合計ジャッジ時間 | 53,283 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
71,204 KB |
testcase_01 | AC | 70 ms
71,092 KB |
testcase_02 | AC | 1,665 ms
311,004 KB |
testcase_03 | AC | 1,625 ms
221,936 KB |
testcase_04 | AC | 1,588 ms
188,008 KB |
testcase_05 | AC | 1,544 ms
170,912 KB |
testcase_06 | AC | 1,526 ms
163,656 KB |
testcase_07 | AC | 1,167 ms
169,240 KB |
testcase_08 | AC | 1,430 ms
165,224 KB |
testcase_09 | AC | 1,349 ms
144,096 KB |
testcase_10 | AC | 1,398 ms
135,268 KB |
testcase_11 | AC | 1,008 ms
125,360 KB |
testcase_12 | AC | 850 ms
118,596 KB |
testcase_13 | AC | 1,046 ms
118,132 KB |
testcase_14 | AC | 1,048 ms
166,444 KB |
testcase_15 | AC | 1,490 ms
220,748 KB |
testcase_16 | AC | 783 ms
158,376 KB |
testcase_17 | AC | 211 ms
91,764 KB |
testcase_18 | AC | 473 ms
131,996 KB |
testcase_19 | AC | 71 ms
71,352 KB |
testcase_20 | AC | 72 ms
71,276 KB |
testcase_21 | AC | 70 ms
71,208 KB |
testcase_22 | AC | 974 ms
137,256 KB |
testcase_23 | AC | 961 ms
135,280 KB |
testcase_24 | AC | 897 ms
138,352 KB |
testcase_25 | AC | 922 ms
138,248 KB |
testcase_26 | AC | 386 ms
109,328 KB |
testcase_27 | AC | 1,578 ms
229,324 KB |
testcase_28 | AC | 1,603 ms
230,400 KB |
testcase_29 | AC | 1,570 ms
215,592 KB |
testcase_30 | AC | 1,336 ms
147,464 KB |
testcase_31 | AC | 1,195 ms
137,008 KB |
testcase_32 | AC | 1,138 ms
137,200 KB |
testcase_33 | AC | 1,441 ms
228,536 KB |
testcase_34 | AC | 824 ms
159,532 KB |
testcase_35 | AC | 421 ms
83,000 KB |
testcase_36 | AC | 405 ms
82,188 KB |
testcase_37 | AC | 387 ms
79,824 KB |
testcase_38 | AC | 413 ms
79,908 KB |
testcase_39 | AC | 139 ms
119,892 KB |
testcase_40 | AC | 137 ms
120,068 KB |
ソースコード
def choice(s): for i in s: return i def remove_edge(f, t, succ, pred, zero): succ[f][t] = succ[f][t] - 1 if succ[f][t] == 0: del succ[f][t] pred[t][f] = pred[t][f] - 1 if pred[t][f] == 0: del pred[t][f] if len(succ[f]) == 0: zero.append(f) N, M = map(int, input().split()) succ = [{} for i in range(N)] pred = [{} for i in range(N)] zero = [] zero_p = 0 start = 0 ans = [] for i in range(M): f, t = map(int, input().split()) succ[f - 1][t - 1] = succ[f - 1].get(t - 1, 0) + 1 pred[t - 1][f - 1] = pred[t - 1].get(f - 1, 0) + 1 for i in range(N): if len(succ[i]) == 0: zero.append(i) while 1: while len(zero) > zero_p: t = zero[zero_p] erase = [] for f in pred[t]: erase += [(f, t)] * succ[f][t] for e in erase: ans.append(e) remove_edge(e[0], e[1], succ, pred, zero) zero_p += 1 if zero_p == N: break while len(succ[start]) == 0: start = (start + 1) % N path = [start] path_s = set(path) while 1: nex = choice(succ[path[-1]]) path.append(nex) if nex in path_s: break path_s.add(nex) for i in range(path.index(nex), len(path) - 1): remove_edge(path[i], path[i + 1], succ, pred, zero) print(N, len(ans)) for i in ans: print(i[0] + 1, i[1] + 1)