結果

問題 No.1605 Matrix Shape
ユーザー 炭酸水炭酸水
提出日時 2022-05-19 21:44:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 954 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 11,840 KB
実行使用メモリ 95,204 KB
最終ジャッジ日時 2023-10-19 06:00:11
合計ジャッジ時間 28,565 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 243 ms
41,404 KB
testcase_01 AC 247 ms
41,404 KB
testcase_02 AC 249 ms
41,404 KB
testcase_03 WA -
testcase_04 AC 254 ms
41,404 KB
testcase_05 AC 253 ms
41,404 KB
testcase_06 WA -
testcase_07 AC 248 ms
41,404 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
testcase_14 WA -
testcase_15 AC 255 ms
41,404 KB
testcase_16 WA -
testcase_17 AC 243 ms
41,404 KB
testcase_18 AC 246 ms
41,404 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1,105 ms
74,056 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 RE -
testcase_33 AC 1,310 ms
87,464 KB
testcase_34 WA -
testcase_35 RE -
testcase_36 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = []
g = [[] for _ in range(2 * 10**5 - 1)]
g_r = [[] for _ in range(2 * 10**5 - 1)]

for _ in range(n):
    u, v = map(int, input().split())
    a.append([u - 1, v - 1])
    g[v - 1].append(u - 1)
    g_r[u - 1].append(v - 1)

order = []
sw = [True for _ in range(2 * 10**5 - 1)]
def dfs(s):
    sw[s] = False
    for i in g[s]:
        if sw[i]:
            dfs(i)
    order.append(s)
dfs(v - 1)

order_R = []
sw = [True for _ in range(2 * 10**5 - 1)]
def dfs(s):
    sw[s] = False
    for i in g[s]:
        if sw[i]:
            dfs(i)
    order_R.append(s)
dfs(order[len(order) - 1])

if len(order_R) != n:
    print(0)
else:
    count = 0
    z = set()
    x = order_R[0]
    y = order_R[-1]
    for i in range(len(order_R) - 1):
        if order_R[i] == y and order_R[i + 1] == x:
            count += 1
        z.add(order_R[i])
    z.add(y)
    
    if count < a.count([y, x]):
        print(len(z))
    else:
        print(1)
0