結果
問題 | No.2464 To DAG |
ユーザー | fiblonaria |
提出日時 | 2023-09-21 13:53:40 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,041 bytes |
コンパイル時間 | 2,033 ms |
コンパイル使用メモリ | 86,876 KB |
実行使用メモリ | 299,364 KB |
最終ジャッジ日時 | 2023-09-21 13:54:36 |
合計ジャッジ時間 | 55,026 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 122 ms
71,172 KB |
testcase_01 | WA | - |
testcase_02 | TLE | - |
testcase_03 | AC | 1,852 ms
218,600 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 780 ms
112,984 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 1,246 ms
221,264 KB |
testcase_16 | AC | 727 ms
156,100 KB |
testcase_17 | AC | 215 ms
89,152 KB |
testcase_18 | AC | 481 ms
135,064 KB |
testcase_19 | AC | 80 ms
71,472 KB |
testcase_20 | AC | 81 ms
71,280 KB |
testcase_21 | AC | 79 ms
71,144 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 395 ms
111,384 KB |
testcase_27 | AC | 1,410 ms
248,028 KB |
testcase_28 | AC | 1,426 ms
231,196 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 1,368 ms
228,524 KB |
testcase_34 | AC | 737 ms
158,812 KB |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | AC | 144 ms
119,588 KB |
testcase_40 | AC | 142 ms
119,660 KB |
ソースコード
def choice(s): ret = s.pop() s.add(ret) return ret def remove_edge(f, t, succ, pred, zero): succ[f].discard(t) pred[t].discard(f) if len(succ[f]) == 0: zero.append(f) N, M = map(int, input().split()) succ = [set() for i in range(N)] pred = [set() 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].add(t - 1) pred[t - 1].add(f - 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] while len(pred[t]) > 0: f = pred[t].pop() ans.append((f, t)) remove_edge(f, t, 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)