Problem:


Articulation Points

Find articulation points of a given undirected graph G(V, E).

A vertex in an undirected graph is an articulation point (or cut vertex) iff removing it disconnects the graph.

Input

|V| |E|
s0 t0
s1 t1
:
s|E|-1 t|E|-1

, where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively.

si and ti represent source and target verticess of i-th edge (undirected).

Output

A list of articulation points of the graph G ordered by name.

Constraints

1 ≤ |V| ≤ 100,000

0 ≤ |E| ≤ 100,000

The graph is connected

There are no parallel edges

There are no self-loops

Sample Input 1

4 4
0 1
0 2
1 2
2 3

Sample Output 1

2

Sample Input 2

5 4
0 1
1 2
2 3
3 4

Sample Output 2

1
2
3



Sample input:
4 4
0 1
0 2
1 2
2 3


Sample output:
2

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""

input:
5 4
0 1
1 2
2 3
3 4

output:
1
2
3
"""

import sys

sys.setrecursionlimit(int(3e6))
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2


def generate_adj_table(_v_info):
    for v_detail in _v_info:
        v_from, v_to = map(int, v_detail)
        init_adj_table[v_from].append(v_to)
        # undirected graph
        init_adj_table[v_to].append(v_from)
    return init_adj_table


def graph_dfs(current, prev):
    global timer
    pre_v[current] = lowest_v[current] = timer
    timer += 1

    color[current] = VISITED_IN_STACK
    for adj in adj_table[current]:
        if color[adj] is UNVISITED:
            parent_v[adj] = current
            # recursive dfs
            graph_dfs(adj, current)
            lowest_v[current] = min(lowest_v[current], lowest_v[adj])
        elif adj is not prev:
            lowest_v[current] = min(lowest_v[current], pre_v[adj])

    return None


def art_points():
    graph_dfs(dfs_root, -1)

    np = 0
    for v in range(1, vertices):
        parent = parent_v[v]
        if parent is dfs_root:
            np += 1
        elif pre_v[parent] <= lowest_v[v]:
            art_set.add(parent)

    if np > 1:
        art_set.add(dfs_root)

    return art_set


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])
    pre_v, parent_v, lowest_v = ([float('inf')] * vertices for _ in range(3))
    init_adj_table = tuple([] for _ in range(vertices))

    timer = 1
    # root
    dfs_root = 0

    art_set = set()
    color = [UNVISITED] * vertices

    adj_table = generate_adj_table(v_info)

    res = art_points()
    print('parent', parent_v, 'preorder', pre_v, 'postorder', lowest_v)
    if not res:
        pass
    else:
        print(*sorted(res), sep='\n')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""

input:
5 4
0 1
1 2
2 3
3 4

output:
1
2
3
"""

import sys

sys.setrecursionlimit(int(1e5))


def dfs_Tarjan(current):
    global timer
    current_children_count = 0
    visited[current] = True
    disc[current] = low[current] = timer
    # timer += 1

    for adj in adj_table[current]:
        if not visited[adj]:
            parent[adj] = current
            current_children_count += 1
            dfs_Tarjan(adj)
            low[current] = min(low[current], low[adj])
            # current vertex is the root of DFS tree
            if parent[current] == -1 and current_children_count > 1:
                art_set.add(current)
            elif parent[current] != -1 and low[adj] >= disc[current]:
                art_set.add(current)

        elif adj != parent[current]:
            low[current] = min(low[current], disc[adj])

    return None


def dfs_init():
    global timer
    for v in range(v_num):
        if not visited[v]:
            dfs_Tarjan(v)
            timer += 1

    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    v_num, e_num = map(int, _input[0].split())
    edges = map(lambda x: x.split(), _input[1:])

    adj_table = tuple([] for _ in range(v_num))
    for edge in edges:
        source, target = map(int, edge)
        adj_table[source].append(target)
        adj_table[target].append(source)

    timer = 0
    art_set = set()
    parent = [-1] * v_num
    visited = [False] * v_num
    disc, low = ([float('inf')] * v_num for _ in range(2))

    dfs_init()
    if art_set:
        print(*sorted(art_set), sep='\n')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""

input:
5 4
0 1
1 2
2 3
3 4

output:
1
2
3
"""

import sys

sys.setrecursionlimit(int(1e5))


def dfs_Tarjan(current):
    global timer
    children = 0
    visited[current] = True
    disc[current] = low[current] = timer
    timer += 1

    for adj in adj_table[current]:
        if not visited[adj]:
            parent[adj] = current
            children += 1
            dfs_Tarjan(adj)
            low[current] = min(low[current], low[adj])
            # current vertex is the root of DFS tree
            if parent[current] == -1 and children > 1:
                art_set.add(current)
            elif low[adj] >= disc[current]:
                art_set.add(current)

        elif adj != parent[current]:
            low[current] = min(low[current], disc[adj])

    return None


def dfs_init():
    for v in range(v_num):
        if not visited[v]:
            dfs_Tarjan(v)

    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    v_num, e_num = map(int, _input[0].split())
    edges = map(lambda x: x.split(), _input[1:])

    adj_table = tuple([] for _ in range(v_num))
    for edge in edges:
        source, target = map(int, edge)
        adj_table[source].append(target)
        adj_table[target].append(source)

    timer = 0
    art_set = set()
    parent = [-1] * v_num
    visited = [False] * v_num
    disc, low = ([float('inf')] * v_num for _ in range(2))

    dfs_init()
    if art_set:
        print(*sorted(art_set), sep='\n')

Submission status: Wrong Answer

Solution code:
def dfs(v, tm):
    visited[v] = True
    dts[v] = est[v] = tm + 1
    child = 0

    for i in range(nv):
        if adj[v][i]:
            if not visited[i]:
                child += 1
                parents[i] = v
                dfs(i, tm + 1)
                est[v] = min(est[v], est[i])

                if parents[v] is None and child > 1:
                    aps[v] = True
                if parents[v] is not None and est[i] >= dts[v]:
                    aps[v] = True
            else:
                if parents[v] != i:
                    est[v] = min(est[v], est[i])

nv, ne = map(int, input().split(' '))
adj = [[False] * nv for _ in range(nv)]
est = [float('inf')] * nv
visited = [False] * nv
parents = [None] * nv
aps = [False] * nv
dts = [0] * nv

for _ in range(ne):
    s, t = map(int, input().split(' '))
    adj[s][t] = adj[t][s] = True

dfs(0, 0)

for i in range(nv):
    if aps[i]:
        print(i)

Submission status: Wrong Answer

Solution code:
def dfs(G,s,p,prenum,T,parents):
    T[s] = set()
    prenum[s] = p
    if len(G[s]) == 0: return p
    for c in G[s]:
        if c in T: continue
        p = dfs(G,c,p+1,prenum,T,parents)
        T[s].add(c)
        T[c].add(s)
        parents[c] = s
    return p




def find(G):
    points = []
    lowest = {}
    prenum = {}
    parents = {0:None}
    T = {}
    dfs(G,0,1,prenum,T,parents)
    for s in G:
        lowest[s] = prenum[s]
        for t in G[s]:
            if not t in T[s]:
                if lowest[s] > prenum[t]:
                    lowest[s] = prenum[t]
    for s in T:
        for t in T[s]:
            if t==parents[s]: continue
            if lowest[s] > lowest[t]:
                lowest[s] = lowest[t]

    for s in T:
        p = parents[s]
        if p is None:
            if len(T[s])-1>1: points.append(s)
        else:
            if parents[p] is None: continue
            if prenum[p] < lowest[s]:
                points.append(p)

    return points

n,m = map(int,raw_input().split(' '))

G = {}
for i in range(n):
    G[i] = set()

for i in range(m):
    s,t = map(int,raw_input().split(' '))
    G[s].add(t)
    G[t].add(s)

points = find(G)
for p in sorted(points):
    print p

Submission status: Wrong Answer

Solution code:
def dfs(G,s,p,prenum,T,parents):
    T[s] = set()
    prenum[s] = p
    if len(G[s]) == 0: return p
    for c in G[s]:
        if c in T: continue
        p = dfs(G,c,p+1,prenum,T,parents)
        T[s].add(c)
        T[c].add(s)
        parents[c] = s
    return p




def find(G):
    points = []
    lowest = {}
    prenum = {}
    parents = {0:None}
    T = {}
    dfs(G,0,1,prenum,T,parents)
    for s in G:
        lowest[s] = prenum[s]
        for t in G[s]:
            if not t in T[s]:
                if lowest[s] > prenum[t]:
                    lowest[s] = prenum[t]
    for s in T:
        for t in T[s]:
            if t==parents[s]: continue
            if lowest[s] > lowest[t]:
                lowest[s] = lowest[t]

    for s in T:
        p = parents[s]
        if p is None:
            if len(T[s])>1: points.append(s)
        else:
            if parents[p] is None: continue
            if prenum[p] < lowest[s]:
                points.append(p)

    return points

n,m = map(int,raw_input().split(' '))

G = {}
for i in range(n):
    G[i] = set()

for i in range(m):
    s,t = map(int,raw_input().split(' '))
    G[s].add(t)
    G[t].add(s)

points = find(G)
for p in sorted(points):
    print p

Submission status: Wrong Answer

Solution code:
def dfs(G,s,p,prenum,T,parents):
    T[s] = set()
    prenum[s] = p
    if len(G[s]) == 0: return p
    for c in G[s]:
        if c in T: continue
        p = dfs(G,c,p+1,prenum,T,parents)
        T[s].add(c)
        T[c].add(s)
        parents[c] = s
    return p




def find(G):
    points = []
    lowest = {}
    prenum = {}
    parents = {0:None}
    T = {}
    dfs(G,0,1,prenum,T,parents)
    for s in G:
        lowest[s] = prenum[s]
        for t in G[s]:
            if not t in T[s]:
                if lowest[s] > prenum[t]:
                    lowest[s] = prenum[t]
    for s in T:
        for t in T[s]:
            if t==parents[s]: continue
            if lowest[s] > lowest[t]:
                lowest[s] = lowest[t]

    for s in T:
        p = parents[s]
        if p is None:
            if len(T[s])>1: points.append(s)
        else:
            if parents[p] is None: continue
            if prenum[p] <= lowest[s]:
                points.append(p)

    return points

n,m = map(int,raw_input().split(' '))

G = {}
for i in range(n):
    G[i] = set()

for i in range(m):
    s,t = map(int,raw_input().split(' '))
    G[s].add(t)
    G[t].add(s)

points = find(G)
for p in sorted(points):
    print p

Submission status: Wrong Answer

Solution code:
def dfs(G,s,p,prenum,T,parents,lowest):
    T[s] = set()
    prenum[s] = p
    lowest[s] = p
    if len(G[s]) == 0: return p
    for c in G[s]:
        if c in T:
            if lowest[s] > prenum[c]:
                lowest[s] = prenum[c]
        else:
            p = dfs(G,c,p+1,prenum,T,parents,lowest)
            T[s].add(c)
            T[c].add(s)
            parents[c] = s
            lowest[s] = min(lowest[s], lowest[c])
    return p




def find(G):
    points = []
    lowest = {}
    prenum = {}
    parents = {0:None}
    T = {}
    dfs(G,0,1,prenum,T,parents,lowest)

    #print G
    #print T
    #print prenum
    #print lowest
    #print parents

    for s in T:
        p = parents[s]
        if p is None:
            if len(T[s])>1: points.append(s)
        else:
            if parents[p] is None: continue
            if prenum[p] <= lowest[s]:
                points.append(p)

    return points

n,m = map(int,raw_input().split(' '))

G = {}
for i in range(n):
    G[i] = set()

for i in range(m):
    s,t = map(int,raw_input().split(' '))
    G[s].add(t)
    G[t].add(s)

points = find(G)
for p in sorted(points):
    print p

Submission status: Wrong Answer

Solution code:
V,E = map(int, input().split())
#??£??\??????????????????
A = [[] for i in range(V)]
for i in range(E):
    s,t = map(int, input().split())
    A[s].append(t)
    A[t].append(s)
    
#?????????????¨???????
prenum = [None for i in range(V)]
#DFS???????????????????????????
parent = [None for i in range(V)]
#????????????????°??????????
lowest = [None for i in range(V)]
#?¨????????????°??????
visited = [False for i in range(V)]

def DFS(u = 0, prev = -1, timer = 0):
    prenum[u] = timer
    lowest[u] = timer
    timer += 1
    visited[u] = True
    
    for v in A[u]:
        if not visited[v]:
            parent[v] = u
            DFS(v, u, timer)
            lowest[u] = min(lowest[u], lowest[v])
        elif v != prev:
            lowest[u] = min(lowest[u], prenum[v])
DFS()

ans = set()
 
for u in range(1, V):
    p = parent[u]
    if prenum[p] <= lowest[u]:
        ans.add(p)
 
if parent.count(0) >= 3:
    ans.add(0)
else:
    ans.discard(0)
 
ans = list(ans)
ans.sort()
 
if ans:
    print(*ans, sep = '\n')

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
from math import isinf
INF = float("inf")
sys.setrecursionlimit(100000)
def dfs(v, tm):
    est[v] = timer = tm + 1
    child = 0
    for i in adj[v]:
        if isinf(est[i]):
            child += 1
            parents[i] = v
            dfs(i, timer)
            est[v] = min(est[v], est[i])
            if parents[v] is None and child > 1: aps[v] = True
            if parents[v] is not None and est[i] >= timer: aps[v] = True
        elif parents[v] != i:
            est[v] = min(est[v], i)
n, m = map(int, stdin.readline().split())
adj = [[] for _ in range(n)]
est = [INF] * n
parents = [None] * n
aps = [False] * n
for _ in range(m):
    s, t = map(int, stdin.readline().split())
    adj[s].append(t)
    adj[t].append(s)
dfs(0, 0)
for i in range(n):
    if aps[i]:
        print(i)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import setrecursionlimit
setrecursionlimit(100000)

def inpl(): return tuple(map(int, input().split()))

V, E = inpl()
graph = [[] for k in range(V)]

for _ in range(E):
    s, t = inpl()
    graph[s].append(t)
    graph[t].append(s)

prenum = [-1] * V
lowest = [float("inf")] * V
found = [False] * V
result = set()
root = 0

def DFS(i, c, prev):
    global root
    prenum[i] = c
    lowest[i] = c
    found[i] = True
    
    for p in graph[i]:
        if found[p]:
            if p != prev:
                lowest[i] = min(lowest[i], prenum[p])
        else:
            c = DFS(p, c+1, i)
            lowest[i] = min(lowest[i], lowest[p])
    
    if prenum[prev] <= lowest[i]:
        result.add(prev)
    if prev == 0:
        root += 1
    
    return c
DFS(0, 1, 0)

if root != 1:
    result = result.difference([0])

for r in result:
    print(r)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 11 20:34:26 2017

@author: TKC
"""
# =========================================
INPUT = """1 0"""
def get_input(inp):
    li = inp.split("\n")

    def inner():
        return li.pop(0)
    return inner

input = get_input(INPUT)

"""
from sys import setrecursionlimit
setrecursionlimit(100000)

from collections import Counter, deque
from heapq import heappush, heappop
from bisect import # https://docs.python.jp/3/library/bisect.html
from itertools import product, combinations

"""
# remoooooooooooooooooooooooooove

# -*- coding: utf-8 -*-
from sys import setrecursionlimit
setrecursionlimit(100000)

def inpl(): return tuple(map(int, input().split()))

V, E = inpl()
graph = [[] for k in range(V)]

for _ in range(E):
    s, t = inpl()
    graph[s].append(t)
    graph[t].append(s)

prenum = [-1] * V
lowest = [float("inf")] * V
found = [False] * V
result = set()
root = 0

def DFS(i, c, prev):
    global root
    prenum[i] = c
    lowest[i] = c
    found[i] = True
    
    for p in graph[i]:
        if found[p]:
            if p != prev:
                lowest[i] = min(lowest[i], prenum[p])
        else:
            c = DFS(p, c+1, i)
            lowest[i] = min(lowest[i], lowest[p])
    
    if prenum[prev] <= lowest[i]:
        result.add(prev)
    if prev == 0:
        root += 1
    
    return c
DFS(0, 1, 0)

if root == 1:
    result = result.difference([0])

for r in result:
    print(r)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import setrecursionlimit
setrecursionlimit(100000)

def inpl(): return tuple(map(int, input().split()))

V, E = inpl()
graph = [[] for k in range(V)]

for _ in range(E):
    s, t = inpl()
    graph[s].append(t)
    graph[t].append(s)

prenum = [-1] * V
lowest = [float("inf")] * V
found = [False] * V
result = set()
root = 0

def DFS(i, c, prev):
    global root
    prenum[i] = c
    lowest[i] = c
    found[i] = True
    
    for p in graph[i]:
        if found[p]:
            if p != prev:
                lowest[i] = min(lowest[i], prenum[p])
        else:
            c = DFS(p, c+1, i)
            lowest[i] = min(lowest[i], lowest[p])
    
    if prenum[prev] <= lowest[i]:
        result.add(prev)
    if prev == 0:
        root += 1
    
    return c
DFS(0, 1, 0)

if root <= 2:
    result = result.difference([0])

for r in result:
    print(r)

Submission status: Wrong Answer

Solution code:
def get_articulation_points(G, N, start=0):
    v_min = [0]*N; order = [None]*N
    result = []; count = 0
    def dfs(v, prev):
        nonlocal count
        r_min = order[v] = count
        fcnt = 0; p_art = 0
        count += 1
        for w in G[v]:
            if w == prev:
                continue
            if order[w] is None:
                ret = dfs(w, v)
                p_art |= (ret == w)
                r_min = min(r_min, ret)
                fcnt += 1
            else:
                r_min = min(r_min, order[w])
        if (prev == -1 and fcnt > 1) or (prev != -1 and p_art):
            result.append(v)
        return r_min
    dfs(start, -1)
    return result

n, m = map(int, input().split())
G = [[] for i in range(n)]
for i in range(m):
    s, t = map(int, input().split())
    G[s].append(t)
    G[t].append(s)
*_,=map(print,sorted(get_articulation_points(G, n)))

Submission status: Wrong Answer

Solution code:

def get_articulation_points(G, N, start=0):
    v_min = [0]*N; order = [None]*N
    result = []; count = 0
    def dfs(v, prev):
        nonlocal count
        r_min = order[v] = count
        fcnt = 0; p_art = 0
        count += 1
        for w in G[v]:
            if w == prev:
                continue
            if order[w] is None:
                ret = dfs(w, v)
                p_art |= (ret == order[w])
                r_min = min(r_min, ret)
                fcnt += 1
            else:
                r_min = min(r_min, order[w])
        p_art |= (r_min == order[v] and len(G[v]) > 1)
        if (prev == -1 and fcnt > 1) or (prev != -1 and p_art):
            result.append(v)
        return r_min
    dfs(start, -1)
    return result

n, m = map(int, input().split())
G = [[] for i in range(n)]
for i in range(m):
    s, t = map(int, input().split())
    G[s].append(t)
    G[t].append(s)
*_,=map(print,sorted(get_articulation_points(G, n)))

Submission status: Wrong Answer

Solution code:
def solve():
    N, M = map(int, input().split())
    edges = [[] for _ in [0] * N]
    for _ in [0] * M:
        a, b = map(int, input().split())
        edges[a].append(b)
        edges[b].append(a)
    for v in sorted(get_lowlink(edges)[1]):
        print(v)


def get_lowlink(edges):
    import sys
    sys.setrecursionlimit(10**7)

    n = len(edges)
    order = [-1] * n
    low = [float("inf")] * n
    bridges = []
    articulations = [0] if len(edges[0]) > 1 else []
    append_bridge, append_articulation = bridges.append, articulations.append

    def dfs(v, prev, k):
        order[v] = low[v] = k

        is_articulation = False
        for dest in edges[v]:
            if order[dest] == -1:
                dfs(dest, v, k + 1)
                if low[v] > low[dest]:
                    low[v] = low[dest]
                if order[v] < low[dest]:
                    append_bridge((v, dest))
                is_articulation |= order[v] <= low[dest]

            elif dest != prev and low[v] > order[dest]:
                low[v] = order[dest]

        if v > 0 and is_articulation:
            append_articulation(v)

    dfs(0, 0, 0)
    return bridges, articulations


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def seq():
    a = 1
    while True:
        yield a
        a += 1

def dfs(here, went, connect, discovery, low, answer, seq):
    went |= {here}
    discovery[here] = low[here] = next(seq)
    child = 0
    for con in connect[here]:
        if con not in went:
            parent[con] = here
            child += 1
            dfs(con, went, connect, discovery, low, answer, seq)
            if parent[here] is None and child >= 2:
                answer.append(here)
            elif parent[here] is not None and discovery[here] <= low[con]:
                answer.append(here)
        elif parent[here] != parent[con]:
            low[here] = min(low[here], discovery[con])

vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
for _ in range(edges):
    v1, v2 = (int(n) for n in input().split(" "))
    connect[v1].append(v2)
    connect[v2].append(v1)
answer = []
new_seq = seq()
went = set()
discovery = [None for n in range(vertices)]
low = [None for n in range(vertices)]
parent = [None for n in range(vertices)]
dfs(0, went, connect, discovery, low, answer, new_seq)
for a in sorted(answer):
    print(a)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def seq():
    a = 1
    while True:
        yield a
        a += 1

def dfs(here, went, connect, discovery, low, answer, seq):
    went |= {here}
    discovery[here] = low[here] = next(seq)
    child = 0
    for con in connect[here]:
        if con not in went:
            parent[con] = here
            child += 1
            dfs(con, went, connect, discovery, low, answer, seq)
            low[here] = min(low[here], low[con])
            if parent[here] is None and child >= 2:
                answer.append(here)
            elif parent[here] is not None and discovery[here] <= low[con]:
                answer.append(here)
        elif parent[here] != parent[con]:
            low[here] = min(low[here], discovery[con])

vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
for _ in range(edges):
    v1, v2 = (int(n) for n in input().split(" "))
    connect[v1].append(v2)
    connect[v2].append(v1)
answer = []
new_seq = seq()
went = set()
discovery = [None for n in range(vertices)]
low = [None for n in range(vertices)]
parent = [None for n in range(vertices)]
dfs(0, went, connect, discovery, low, answer, new_seq)
for a in sorted(answer):
    print(a)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def seq():
    a = 1
    while True:
        yield a
        a += 1

def dfs(here, went, connect, discovery, low, answer, seq):
    went |= {here}
    discovery[here] = low[here] = next(seq)
    child = 0
    for con in connect[here]:
        if con not in went:
            parent[con] = here
            child += 1
            dfs(con, went, connect, discovery, low, answer, seq)
            low[here] = min(low[here], low[con])
            if parent[here] is None and child >= 2:
                answer.append(here)
            elif parent[here] is not None and discovery[here] <= low[con]:
                answer.append(here)
        elif parent[here] != con:
            low[here] = min(low[here], discovery[con])

vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
for _ in range(edges):
    v1, v2 = (int(n) for n in input().split(" "))
    connect[v1].append(v2)
    connect[v2].append(v1)
answer = []
new_seq = seq()
went = set()
discovery = [None for n in range(vertices)]
low = [None for n in range(vertices)]
parent = [None for n in range(vertices)]
dfs(0, went, connect, discovery, low, answer, new_seq)
for a in sorted(answer):
    print(a)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def seq():
    a = 0
    while True:
        yield a
        a += 1

def dfs(here, went, connect, discovery, low, answer, seq):
    went |= {here}
    discovery[here] = low[here] = next(seq)
    child = 0
    for con in connect[here]:
        if con not in went:
            parent[con] = here
            child += 1
            dfs(con, went, connect, discovery, low, answer, seq)
            low[here] = min(low[here], low[con])
            if parent[here] is None and child >= 2:
                answer.append(here)
            elif parent[here] is not None and discovery[here] <= low[con]:
                answer.append(here)
        elif parent[here] != con:
            low[here] = min(low[here], discovery[con])

vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
for _ in range(edges):
    v1, v2 = (int(n) for n in input().split(" "))
    connect[v1].append(v2)
    connect[v2].append(v1)
answer = []
new_seq = seq()
went = set()
discovery = [0 for n in range(vertices)]
low = [float("inf") for n in range(vertices)]
parent = [None for n in range(vertices)]
dfs(0, went, connect, discovery, low, answer, new_seq)
for a in sorted(answer):
    print(a)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def seq():
    a = 1
    while True:
        yield a
        a += 1

def dfs(here, went, connect, discovery, low, answer, seq):
    went |= {here}
    discovery[here] = low[here] = next(seq)
    child = 0
    for con in connect[here]:
        if con not in went:
            parent[con] = here
            child += 1
            dfs(con, went, connect, discovery, low, answer, seq)
            low[here] = min(low[here], low[con])
            if parent[here] is None and child >= 2:
                answer.append(here)
            elif parent[here] is not None and discovery[here] <= low[con]:
                answer.append(here)
        elif parent[here] != con:
            low[here] = min(low[here], discovery[con])

vertices, edges = (int(n) for n in input().split(" "))
connect = defaultdict(list)
for _ in range(edges):
    v1, v2 = (int(n) for n in input().split(" "))
    connect[v1].append(v2)
    connect[v2].append(v1)
answer = []
new_seq = seq()
went = set()
discovery = [0 for n in range(vertices)]
low = [float("inf") for n in range(vertices)]
parent = [None for n in range(vertices)]
dfs(0, went, connect, discovery, low, answer, new_seq)
for a in sorted(answer):
    print(a)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
V, E = map(int, input().split())
G = defaultdict(list)
T = defaultdict(list)
for i in range(E):
    s,t = map(int, input().split())
    G[s].append(t)
    G[t].append(s)

prenum = [float('inf')] * V
lowest = [float('inf')] * V
parent = [None] * V
visited = [False] * V

def dfs(g,s,c=0,p=None):    
    visited[s] = True
    prenum[s] = c
    lowest[s] = c
    c+=1    
    for v in g[s]:
        if not visited[v]:
            parent[v] = s
            T[v].append(s)
            dfs(g,v,c,s)
            lowest[s] = min( lowest[s], lowest[v] )
        elif v != p:
            lowest[s] = min( lowest[s], prenum[v] )

dfs(G,0)
k = []
if len(T[0]) > 1: k.append(0)
for u in range(V):
    p = parent[u]
    if p is None or p == 0: continue
    if prenum[p] <= lowest[u]: k.append(p)
for i in sorted(k):
    print(i)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
V, E = map(int, input().split())
G = defaultdict(list)
T = defaultdict(list)
for i in range(E):
    s,t = map(int, input().split())
    G[s].append(t)
    G[t].append(s)

prenum = [float('inf')] * V
lowest = [float('inf')] * V
parent = [None] * V
visited = [False] * V

def dfs(g,s,c=0,p=None):    
    visited[s] = True
    prenum[s] = c
    lowest[s] = c
    c+=1    
    for v in g[s]:
        if not visited[v]:
            parent[v] = s
            T[v].append(s)
            T[s].append(v)
            dfs(g,v,c,s)
            lowest[s] = min( lowest[s], lowest[v] )
        elif v != p:
            lowest[s] = min( lowest[s], prenum[v] )

dfs(G,0)
k = []
if len(T[0]) > 1: k.append(0)
for u in range(V):
    p = parent[u]
    if p is None or p == 0: continue
    if prenum[p] <= lowest[u]: k.append(p)
for i in sorted(k):
    print(i)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


if __name__ == '__main__':

    n, m = [int(s) for s in input().split()]
    E = [set() for _ in range(n)]
    for _ in range(m):
        s, t = [int(s) for s in input().split(" ")]
        E[s].add(t)

    def dfs(current, prev):
        global timer
        prenum[current] = timer
        lowest[current] = prenum[current]
        timer += 1

        visited[current] = 1

        for v in E[current]:
            if visited[v] == 0:
                parent[v] = current
                dfs(v, current)
                lowest[current] = min(lowest[current], lowest[v])
            elif v != prev:  # current -> v is back-edge
                lowest[current] = min(lowest[current], prenum[v])

    prenum = [None] * n
    parent = [None] * n
    lowest = [float("inf")] * n
    timer = 1
    visited = [0] * n

    dfs(0, -1)

    ap = []
    np = 0
    for i in range(1, n):
        p = parent[i]
        if p == 0:
            np += 1
        elif prenum[p] <= lowest[i]:
            ap.append(p)

    if np > 1:
        ap.append(0)

    ap.sort()
    if ap:
        print("\n".join(map(str, ap)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


if __name__ == '__main__':

    n, m = [int(s) for s in input().split()]
    E = [set() for _ in range(n)]
    for _ in range(m):
        s, t = [int(s) for s in input().split(" ")]
        E[s].add(t)
        E[t].add(s)

    def dfs(current, prev):
        global timer
        prenum[current] = timer
        lowest[current] = prenum[current]
        timer += 1

        visited[current] = 1

        for v in E[current]:
            if visited[v] == 0:
                parent[v] = current
                dfs(v, current)
                lowest[current] = min(lowest[current], lowest[v])
            elif v != prev:  # current -> v is back-edge
                lowest[current] = min(lowest[current], prenum[v])

    prenum = [None] * n
    parent = [None] * n
    lowest = [float("inf")] * n
    timer = 1
    visited = [0] * n

    dfs(0, -1)

    ap = []
    np = 0
    for i in range(1, n):
        p = parent[i]
        if p == 0:
            np += 1
        elif prenum[p] <= lowest[i]:
            ap.append(p)

    if np > 1:
        ap.append(0)

    ap.sort()
    if ap:
        print("\n".join(map(str, ap)))