init
This commit is contained in:
commit
851751ea87
82 changed files with 2093 additions and 0 deletions
54
2D.py
Normal file
54
2D.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import sys
|
||||
|
||||
data = sys.stdin.read().split()
|
||||
if not data:
|
||||
sys.exit()
|
||||
n = int(data[0])
|
||||
m = int(data[1])
|
||||
adj = [[] for _ in range(n + 1)]
|
||||
idx = 2
|
||||
for i in range(1, m + 1):
|
||||
u = int(data[idx])
|
||||
v = int(data[idx+1])
|
||||
idx += 2
|
||||
adj[u].append((v, i))
|
||||
adj[v].append((u, i))
|
||||
tin = [-1] * (n + 1)
|
||||
fup = [-1] * (n + 1)
|
||||
ans = []
|
||||
timer = 0
|
||||
ptr = [0] * (n + 1)
|
||||
stack = []
|
||||
for i in range(1, n + 1):
|
||||
if tin[i] == -1:
|
||||
tin[i] = fup[i] = timer
|
||||
timer += 1
|
||||
stack.append((i, -1))
|
||||
while stack:
|
||||
v, p_e = stack[-1]
|
||||
if ptr[v] < len(adj[v]):
|
||||
to, e_idx = adj[v][ptr[v]]
|
||||
ptr[v] += 1
|
||||
|
||||
if e_idx == p_e:
|
||||
continue
|
||||
|
||||
if tin[to] != -1:
|
||||
if tin[to] < fup[v]:
|
||||
fup[v] = tin[to]
|
||||
else:
|
||||
tin[to] = fup[to] = timer
|
||||
timer += 1
|
||||
stack.append((to, e_idx))
|
||||
else:
|
||||
stack.pop()
|
||||
if stack:
|
||||
p_v, _ = stack[-1]
|
||||
if fup[v] < fup[p_v]:
|
||||
fup[p_v] = fup[v]
|
||||
if fup[v] > tin[p_v]:
|
||||
ans.append(p_e)
|
||||
ans.sort()
|
||||
print(len(ans))
|
||||
if ans:
|
||||
print(*(ans))
|
||||
Loading…
Add table
Add a link
Reference in a new issue