結果

問題 No.3482 Quod Erat Demonstrandum
コンテスト
ユーザー kidodesu
提出日時 2026-03-27 22:00:32
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 1,068 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 184 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 119,864 KB
最終ジャッジ日時 2026-03-27 22:00:55
合計ジャッジ時間 22,275 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 23 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def main():
    n, m = list(map(int, input().split()))
    node = [[] for _ in range(n)]
    for _ in range(m):
        u, v, x = list(map(lambda x: int(x)-1, input().split()))
        node[u].append((v, x))
    D = [-1] * n
    D[0] = 0
    E = [-1] * n
    E[0] = 0
    B = [0]
    while A:= B:
        B = []
        for now in A:
            for nxt, x in node[now]:
                if D[nxt] == -1:
                    if x == 0:
                        D[nxt] = D[now]+1
                        E[nxt] = E[now]
                        B.append(nxt)
                    else:
                        if E[now]:
                            continue
                        else:
                            D[nxt] = D[now]+1
                            E[nxt] = 1
                            B.append(nxt)
    if D[n-1] == -1:
        print("Unknown")
        return 0
    elif E[n-1] == 0:
        print("Same")
        return D[n-1]
    else:
        print("Different")
        return D[n-1]

for _ in range(int(input())):
    ans = main()
    if ans: print(ans)
0