結果

問題 No.2464 To DAG
ユーザー mkawa2mkawa2
提出日時 2023-09-08 22:57:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,601 bytes
コンパイル時間 710 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 199,760 KB
最終ジャッジ日時 2023-09-08 22:57:53
合計ジャッジ時間 27,138 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,176 KB
testcase_01 AC 65 ms
70,984 KB
testcase_02 AC 581 ms
199,760 KB
testcase_03 WA -
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 WA -
testcase_13 WA -
testcase_14 AC 454 ms
119,632 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 68 ms
71,220 KB
testcase_20 AC 67 ms
71,112 KB
testcase_21 AC 65 ms
71,264 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 213 ms
89,800 KB
testcase_27 AC 701 ms
147,764 KB
testcase_28 AC 708 ms
147,724 KB
testcase_29 AC 668 ms
146,060 KB
testcase_30 AC 527 ms
131,144 KB
testcase_31 AC 532 ms
128,064 KB
testcase_32 AC 497 ms
132,668 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 75 ms
80,472 KB
testcase_40 AC 76 ms
80,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
        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])
0