結果
問題 | No.2464 To DAG |
ユーザー | mkawa2 |
提出日時 | 2023-09-08 23:03:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 769 ms / 2,000 ms |
コード長 | 1,628 bytes |
コンパイル時間 | 335 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 199,680 KB |
最終ジャッジ日時 | 2024-06-26 16:23:05 |
合計ジャッジ時間 | 27,538 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,096 KB |
testcase_01 | AC | 38 ms
52,608 KB |
testcase_02 | AC | 605 ms
199,680 KB |
testcase_03 | AC | 757 ms
146,016 KB |
testcase_04 | AC | 714 ms
141,056 KB |
testcase_05 | AC | 703 ms
140,160 KB |
testcase_06 | AC | 721 ms
139,904 KB |
testcase_07 | AC | 554 ms
120,556 KB |
testcase_08 | AC | 626 ms
128,780 KB |
testcase_09 | AC | 592 ms
123,812 KB |
testcase_10 | AC | 592 ms
123,988 KB |
testcase_11 | AC | 431 ms
108,860 KB |
testcase_12 | AC | 362 ms
101,184 KB |
testcase_13 | AC | 444 ms
111,148 KB |
testcase_14 | AC | 520 ms
118,832 KB |
testcase_15 | AC | 646 ms
135,660 KB |
testcase_16 | AC | 395 ms
107,628 KB |
testcase_17 | AC | 117 ms
80,896 KB |
testcase_18 | AC | 237 ms
94,848 KB |
testcase_19 | AC | 36 ms
52,608 KB |
testcase_20 | AC | 36 ms
52,480 KB |
testcase_21 | AC | 39 ms
52,608 KB |
testcase_22 | AC | 428 ms
129,452 KB |
testcase_23 | AC | 450 ms
129,504 KB |
testcase_24 | AC | 414 ms
130,272 KB |
testcase_25 | AC | 417 ms
129,976 KB |
testcase_26 | AC | 203 ms
88,704 KB |
testcase_27 | AC | 762 ms
146,888 KB |
testcase_28 | AC | 769 ms
146,688 KB |
testcase_29 | AC | 749 ms
145,072 KB |
testcase_30 | AC | 621 ms
128,700 KB |
testcase_31 | AC | 574 ms
126,340 KB |
testcase_32 | AC | 576 ms
126,096 KB |
testcase_33 | AC | 653 ms
141,896 KB |
testcase_34 | AC | 375 ms
107,248 KB |
testcase_35 | AC | 372 ms
133,588 KB |
testcase_36 | AC | 371 ms
133,588 KB |
testcase_37 | AC | 350 ms
133,580 KB |
testcase_38 | AC | 338 ms
133,792 KB |
testcase_39 | AC | 50 ms
70,016 KB |
testcase_40 | AC | 48 ms
70,528 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(1000005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = -1-(-1 << 63) # md = 10**9+7 md = 998244353 def dfs(u): uu, ii = [u], [] vis[u] = 1 while uu: u = uu[-1] v = i = -1 while to[u] and use[i]: v, i = to[u].pop() if use[i]: vis[u] = 0 uu.pop() if ii:ii.pop() elif vis[v]: dead[i] = 1 use[i] = 1 while uu[-1] != v: u = uu.pop() vis[u] = 0 i = ii.pop() dead[i] = 1 else: uu.append(v) ii.append(i) use[i] = 1 vis[v] = 1 n, m = LI() to = [[] for _ in range(n)] uv = [] for i in range(m): u, v = LI1() to[u].append((v, i)) uv.append((u+1, v+1)) dead = [0]*m use = [0]*m+[1] vis = [0]*n for u in range(n): if not to[u]: continue dfs(u) print(n, m-sum(dead)) for i in range(m): if dead[i]: continue print(*uv[i])