結果
| 問題 |
No.1254 補強への架け橋
|
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-03-06 00:45:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 789 ms / 2,000 ms |
| コード長 | 1,695 bytes |
| コンパイル時間 | 455 ms |
| コンパイル使用メモリ | 82,596 KB |
| 実行使用メモリ | 214,304 KB |
| 最終ジャッジ日時 | 2025-03-06 00:45:51 |
| 合計ジャッジ時間 | 30,488 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 123 |
ソースコード
from collections import defaultdict, deque
import sys
sys.setrecursionlimit(10 ** 6)
def lowlink(n, adj):
bridges = []
articulation_points = []
used = [False] * n
order = [0] * n
low = [0] * n
def dfs(now, parent, count):
used[now] = True
order[now] = count
low[now] = order[now]
count += 1
isarticulation = False # 間接点か
nchildren = 0
for to in adj[now]:
if used[to]:
# 訪問済みの頂点 = 後退辺
if to != parent:
low[now] = min(low[now], order[to])
else:
nchildren += 1
count = dfs(to, now, count)
if to != parent:
low[now] = min(low[now], low[to])
if parent != -1 and order[now] <= low[to]:
isarticulation = True
if order[now] < low[to]:
bridges.append((now, to))
if parent == -1 and nchildren >= 2:
isarticulation = True
if isarticulation:
articulation_points.append(now)
return count
count = 0
for i in range(n):
if used[i]: continue
count = dfs(i, -1, count)
return bridges, articulation_points
N = int(input())
edge2id = {}
adj = defaultdict(list)
for i in range(N):
a, b = map(lambda x: int(x)-1, input().split())
adj[a].append(b)
adj[b].append(a)
edge2id[a, b] = i
bridges, _ = lowlink(N, adj)
bs = set(bridges)
ans = []
for a, b in edge2id.keys():
if (a, b) in bs: continue
if (b, a) in bs: continue
ans.append(edge2id[a, b] + 1)
print(len(ans))
print(*ans)
norioc