結果
| 問題 |
No.1254 補強への架け橋
|
| コンテスト | |
| ユーザー |
proribone
|
| 提出日時 | 2020-10-10 14:58:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 505 ms / 2,000 ms |
| コード長 | 859 bytes |
| コンパイル時間 | 209 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 202,496 KB |
| 最終ジャッジ日時 | 2024-07-20 15:59:33 |
| 合計ジャッジ時間 | 23,153 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 123 |
ソースコード
import sys
sys.setrecursionlimit(10**9)
pos=-1
def dfs(G,v,p):
global pos
seen[v]=True
hist.append(v)
for nv in G[v]:
if nv==p:
continue
if finished[nv]:
continue
if seen[nv] and (not finished[nv]):
pos=nv
return
dfs(G,nv,v)
if pos!=-1:
return
hist.pop()
finished[v]=True
N=int(input())
G=[[] for _ in range(N)]
Edge=[]
for i in range(N):
a,b=map(lambda x:int(x)-1,input().split())
G[a].append(b)
G[b].append(a)
Edge.append((a,b))
seen=[False]*N
finished=[False]*N
hist=[]
dfs(G,0,-1)
cycle=set()
while(hist):
t=hist[-1]
cycle.add(t)
hist.pop()
if t==pos:
break
ans=[]
for i,e in enumerate(Edge):
if e[0] in cycle and e[1] in cycle:
ans.append(i+1)
print(len(ans))
print(*ans)
proribone