結果

問題 No.1254 補強への架け橋
ユーザー ayaoni
提出日時 2020-10-29 23:32:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 802 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,556 KB
実行使用メモリ 119,324 KB
最終ジャッジ日時 2024-07-21 22:46:00
合計ジャッジ時間 20,167 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 111 RE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N = I()
Graph = [[] for _ in range(N+1)]
dict_edge = {}
for i in range(1,N+1):
    a,b = MI()
    Graph[a].append(b)
    Graph[b].append(a)
    dict_edge[(a,b)] = i
    dict_edge[(b,a)] = i

flag = [0]*(N+1)
previous = [0]*(N+1)
ANS = []


def dfs(i,par):
    flag[i] = 1
    for j in Graph[i]:
        if j == par:
            continue
        elif flag[j] == 0:
            flag[j] = 1
            previous[j] = i
            dfs(j,i)
        else:
            ANS.append(dict_edge[(i,j)])
            k = i
            while k != j:
                ANS.append(dict_edge[k,previous[k]])
                k = previous[k]
        break


dfs(1,0)
print(len(ANS))
print(*ANS)
0