結果

問題 No.1865 Make Cycle
ユーザー puznekopuzneko
提出日時 2022-04-07 23:05:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,175 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 176,236 KB
最終ジャッジ日時 2023-08-18 19:01:34
合計ジャッジ時間 12,978 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 439 ms
124,472 KB
testcase_01 AC 315 ms
103,624 KB
testcase_02 AC 476 ms
129,460 KB
testcase_03 AC 263 ms
106,344 KB
testcase_04 AC 462 ms
148,224 KB
testcase_05 WA -
testcase_06 AC 486 ms
135,488 KB
testcase_07 AC 439 ms
129,548 KB
testcase_08 AC 414 ms
122,796 KB
testcase_09 WA -
testcase_10 AC 551 ms
154,356 KB
testcase_11 AC 545 ms
148,852 KB
testcase_12 AC 376 ms
121,640 KB
testcase_13 AC 397 ms
121,628 KB
testcase_14 AC 389 ms
123,624 KB
testcase_15 AC 523 ms
136,696 KB
testcase_16 AC 528 ms
142,600 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 658 ms
158,928 KB
testcase_20 AC 71 ms
71,036 KB
testcase_21 WA -
testcase_22 AC 75 ms
71,248 KB
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin

n, q, *indata = map(int, stdin.read().split())
offset = 0
left = 0
right = q+1
while right - left >= 2:
    mid = (right + left) // 2
    g = [[] for i in range(n)]
    for i in range(mid):
        s, t = indata[i*2]-1,indata[i*2+1]-1
        g[s].append(t)
    check = [0 for j in range(n)]
    cyclecheck = False
    for j in range(n):
        if check[j] == 0:
            que = [(j,0)]
            while que:
                now, inout = que.pop()
                if inout == 0:
                    if check[now] == 0:
                        que.append((now,1))
                        check[now] = 1
                        for k in g[now]:
                            if check[k] == 1:
                                cyclecheck = True
                                break
                            elif check[k] == 0:
                                que.append((k,0))
                        if cyclecheck:
                            break
                else:
                    check[now] = 2
            if cyclecheck:
                break
    if cyclecheck:
        right = mid
    else:
        left = mid

print("{}".format(right))
0