結果

問題 No.2464 To DAG
ユーザー mkawa2mkawa2
提出日時 2023-09-08 22:24:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,415 bytes
コンパイル時間 681 ms
コンパイル使用メモリ 11,064 KB
実行使用メモリ 175,524 KB
最終ジャッジ日時 2023-09-08 22:24:44
合計ジャッジ時間 33,441 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,236 KB
testcase_01 AC 16 ms
8,232 KB
testcase_02 TLE -
testcase_03 AC 1,872 ms
117,708 KB
testcase_04 AC 1,818 ms
116,052 KB
testcase_05 AC 1,848 ms
115,608 KB
testcase_06 AC 1,907 ms
115,364 KB
testcase_07 AC 1,218 ms
81,460 KB
testcase_08 AC 1,544 ms
96,116 KB
testcase_09 AC 1,529 ms
91,732 KB
testcase_10 AC 1,590 ms
94,028 KB
testcase_11 AC 1,073 ms
68,652 KB
testcase_12 AC 835 ms
56,800 KB
testcase_13 AC 1,160 ms
71,916 KB
testcase_14 AC 1,182 ms
80,400 KB
testcase_15 AC 1,492 ms
101,024 KB
testcase_16 AC 828 ms
59,956 KB
testcase_17 AC 114 ms
16,088 KB
testcase_18 AC 486 ms
38,784 KB
testcase_19 AC 16 ms
8,076 KB
testcase_20 AC 16 ms
8,120 KB
testcase_21 AC 16 ms
8,096 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(300005)
# 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):
    vis[u]=1
    for v,i in to[u]:
        if dead[i]:continue
        if vis[v]==2:continue
        if vis[v]==1:
            vis[u]=0
            dead[i]=1
            return v
        r=dfs(v)
        if r==u:
            dead[i]=1
        elif r!=-1:
            dead[i]=1
            vis[u]=0
            return r
    vis[u]=2
    return -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
vis=[0]*n
for u in range(n):
    if vis[u]:continue
    dfs(u)

print(n,m-sum(dead))
for i in range(m):
    if dead[i]:continue
    print(*uv[i])
0