結果

問題 No.1254 補強への架け橋
ユーザー roaris
提出日時 2020-11-15 12:36:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 960 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 193,432 KB
最終ジャッジ日時 2024-07-23 01:11:12
合計ジャッジ時間 23,778 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 WA * 108
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5+10)
from collections import *

def dfs(v, pv):
    global pos
    
    seen[v] = True
    hist.append(v)
    
    for nv in G[v]:
        if nv==pv:
            continue
        
        if finished[nv]:
            continue
        
        if seen[nv] and not finished[nv]:
            pos = nv
            return
        
        dfs(nv, v)
        
        if pos!=-1:
            return
    
    hist.pop()
    finished[v] = True

N = int(input())
G = [[] for _ in range(N)]
edges = defaultdict(int)

for i in range(N):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
    edges[(min(a-1, b-1), max(a-1, b-1))] = i

pos = -1
seen = [False]*N
finished = [False]*N
hist = []
dfs(0, -1)
ans = []

for i in range(len(hist)):
    u, v = hist[i], hist[(i+1)%len(hist)]
    u, v = min(u, v), max(u, v)
    ans.append(edges[(u, v)]+1)

print(len(ans))
print(*ans)
0