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: Accepted

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(1e6))


def generate_adj_table(_v_info):
    for v_detail in _v_info:
        source, target = map(int, v_detail)
        init_adj_table[source].append(target)
        init_adj_table[target].append(source)
    return init_adj_table


def Tarjan(current, parents, visited, disc, low):
    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]:
            parents[adj] = current
            current_children_count += 1

            Tarjan(adj, parents, visited, disc, low)

            low[current] = min(low[current], low[adj])
            # current is root of DFS tree
            if parents[current] == -1 and current_children_count > 1:
                art_set.add(current)

            elif parents[current] != -1 and low[adj] >= disc[current]:
                art_set.add(current)

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

    # print(timer, parents, visited, disc, low)
    return None


def art_points():
    parents = [-1] * vertices
    visited = [False] * vertices
    disc = [float('inf')] * vertices
    low = [float('inf')] * vertices

    for v in range(vertices):
        if not visited[v]:
            Tarjan(v, parents, visited, disc, low)

    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:])
    init_adj_table = tuple([] for _ in range(vertices))
    adj_table = generate_adj_table(v_info)

    timer = 0
    art_set = set()
    ans = art_points()
    if ans:
        print(*sorted(ans), sep='\n')

Submission status: Accepted

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(1e6))


def generate_adj_table(_v_info):
    for v_detail in _v_info:
        source, target = map(int, v_detail)
        init_adj_table[source].append(target)
        init_adj_table[target].append(source)
    return init_adj_table


def Tarjan(current, parents, visited, disc, low):
    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]:
            parents[adj] = current
            current_children_count += 1

            Tarjan(adj, parents, visited, disc, low)

            low[current] = min(low[current], low[adj])
            # current is root of DFS tree
            if parents[current] == -1 and current_children_count > 1:
                art_set.add(current)
            elif parents[current] != -1 and low[adj] >= disc[current]:
                art_set.add(current)

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

    return None


def art_points():
    parents = [-1] * vertices
    visited = [False] * vertices
    disc = [float('inf')] * vertices
    low = [float('inf')] * vertices

    for v in range(vertices):
        if not visited[v]:
            Tarjan(v, parents, visited, disc, low)

    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:])
    init_adj_table = tuple([] for _ in range(vertices))
    adj_table = generate_adj_table(v_info)

    timer = 0
    art_set = set()

    ans = art_points()
    if ans:
        print(*sorted(ans), sep='\n')

Submission status: Accepted

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 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():
    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: Accepted

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])
            if parent[current] == -1 and children > 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():
    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: Accepted

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, visited, disc, low, parent):
    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, visited, disc, low, parent)
            low[current] = min(low[current], low[adj])
            if parent[current] == -1 and children > 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():
    parent = [-1] * v_num
    visited = [False] * v_num
    disc, low = ([float('inf')] * v_num for _ in range(2))

    for v in range(v_num):
        if not visited[v]:
            dfs_Tarjan(v, visited, disc, low, parent)

    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()
    # generate articulation points set
    dfs_init()
    if art_set:
        print(*sorted(art_set), sep='\n')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

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

    for i in adj[v]:
        if est[i] == float('inf'):
            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

        elif parents[v] != i:
            est[v] = min(est[v], dts[i])

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

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

dfs(0, 0)

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

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) >= 2:
    ans.add(0)
else:
    ans.discard(0)
  
ans = list(ans)
ans.sort()
  
if ans:
    print(*ans, sep = '\n')

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(100000)

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

    for i in adj[v]:
        if est[i] == float('inf'):
            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

        elif parents[v] != i:
            est[v] = min(est[v], dts[i])


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

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

dfs(0, 0)

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

Submission status: Accepted

Solution code:
from sys import stdin
import sys
from math import isinf
INF = float("inf")
sys.setrecursionlimit(100000)
def dfs(v, tm):
    dts[v] = est[v] = tm + 1
    child = 0
    for i in adj[v]:
        if isinf(est[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
        elif parents[v] != i:
            est[v] = min(est[v], dts[i])
n, m = map(int, stdin.readline().split())
adj = [[] for _ in range(n)]
est = [float('inf')] * n
parents = [None] * n
aps = [False] * n
dts = [0] * 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: Accepted

Solution code:
from sys import stdin
import sys
from math import isinf
INF = float("inf")
sys.setrecursionlimit(100000)
def dfs(v, tm):
    dts[v] = est[v] = tm + 1
    child = 0
    for i in adj[v]:
        if est[i] == float('inf'):
            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
        elif parents[v] != i:
            est[v] = min(est[v], dts[i])
n, m = map(int, stdin.readline().split())
adj = [[] for _ in range(n)]
est = [float('inf')] * n
parents = [None] * n
aps = [False] * n
dts = [0] * 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: Accepted

Solution code:
import sys
from collections import defaultdict

sys.setrecursionlimit(2000000)

V, E = map(int, input().split())

Edges = defaultdict(set)

for i in range(E):
    s, t = map(int, input().split())
    Edges[s].add(t)
    Edges[t].add(s) 
    
preord = [None] * V 
parent = [None] * V 
lowlink = [None] * V
isVisited = [False] * V
counter = 0

def DFS(cur, prev):
    global counter
    preord[cur] = lowlink[cur] = counter
    isVisited[cur] = True
    counter += 1
    
    for edge in Edges[cur]: 
        if not isVisited[edge]: 
            parent[edge] = cur
            DFS(edge, cur)
            lowlink[cur] = min(lowlink[cur], lowlink[edge])
        elif edge != prev: 
                lowlink[cur] = min(lowlink[cur], preord[edge])
        
DFS(0,-1) 

art_point = [False] * V
r = 0

for _ in filter(lambda x: x == 0, parent):
    r += 1
    if r > 1:
        art_point[0] = True
        break

for i in range(1, V):
    p = parent[i]
    if p and preord[p] <= lowlink[i]:
        art_point[p] = True
 
for i, e in enumerate(art_point):
    if e: print(i)

Submission status: Accepted

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
parent = [-1] * 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)
    parent[i] = prev
    
    return c
DFS(0, 1, 0)

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

for r in sorted(result):
    print(r)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
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 |= (order[v] <= ret)
                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: Accepted

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, M)[1]):
        print(v)


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

    n = len(edges)
    order = [-1] * n
    low = [float("inf")] * n
    bridges = []
    articulations = [0] if edge_num == n-1 and 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: Accepted

Solution code:
from collections import defaultdict
import sys
sys.setrecursionlimit(100000)

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[here] = 1
            elif parent[here] is not None and discovery[here] <= low[con]:
                answer[here] = 1
        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 = [0 for n in range(vertices)]
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 i,n in enumerate(answer):
    if n:
        print(i)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
sys.setrecursionlimit(100*sys.getrecursionlimit())
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(set(k)):
    print(i)

Submission status: Accepted

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

import sys
sys.setrecursionlimit(200000)


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 = list(set(ap))
    ap.sort()
    if ap:
        print("\n".join(map(str, ap)))

Submission status: Accepted

Solution code:
from math import inf
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)


def dfs(v,par):
    global cur
    vis[v]=1 ; disc[v]=cur ;low[v]=cur ; child=0 
    cur+=1
    for i in g[v]:
        if vis[i]==0:
            child+=1
            dfs(i,v)
            low[v]=min(low[i],low[v])
            if par==-1 and child>1:
                apts.add(v)
            if par!=-1 and low[i]>=disc[v]:
                apts.add(v)

        elif i!=par: low[v]=min(disc[i],low[v])
   
def articulation_pts():
    global apts,disc,low,vis
    disc=[0]*n ; low=[inf]*n ; vis=[0]*n ; par=[-1]*n ; apts=set()  
    for i in range(n):
        if vis[i]==0:
            dfs(i,-1)

n,e=map(int,input().split())
cur=0
g=[[] for i in range(n)]
for i in range(e):
    x,y=map(int,input().split())
    g[x].append(y)
    g[y].append(x)
articulation_pts()
apts=sorted(apts)
for i in apts:
    print(i)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit
input = stdin.readline
setrecursionlimit(500*500) #追加

from collections import defaultdict, deque

infty = 2 ** 30

dic = defaultdict(lambda: [-1, infty])

#from sys import stdin
#stdin = open('./chapter15/sample.txt')          # 冒頭にこの1行を追加

#print(stdin.readline().rstrip())    # sample.txtから1行読み込まれる
lines = stdin.readlines()

v, e = map(int, lines[0].split())

glist = [[] for i in range(v)]
parent = [-1] * v
for i in range(e):
    s, t = map(int, lines[i+1].split())
    glist[s].append(t)
    glist[t].append(s)


t = 0
def depthFirstSearch(current, prev):
    global t
    t += 1
    dic[current][0] = t #prenum
    if dic[current][1] > t:
        dic[current][1] = t
    for y in range(len(glist[current])):
        next = glist[current][y]
        if dic[next][0] == -1:
            parent[next] = current
            depthFirstSearch(next,current)
            if dic[current][1] > dic[next][1]:
                dic[current][1] = dic[next][1]
        elif next != prev:
            if dic[current][1] > dic[next][0]:
                dic[current][1] = dic[next][0]
    return

def art_points():
    #lowest no keisan
    depthFirstSearch(0, -1)
    np = 0
    ap = set()
    for i in range(1, v):
        p = parent[i]
        if p == 0:
            np += 1
        elif dic[p][0] <= dic[i][1]:
            ap.add(p)
    if np > 1:
        ap.add(0)

    ap = sorted(list(ap))
    for i in range(len(ap)):
        print(ap[i])

art_points()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)

v, e = list(map(int, input().split()))

G = [[] for _ in range(v)]
for _ in range(e):
    s, t = map(int, input().split())
    G[s].append(t)
    G[t].append(s)


def solve():
    
    used = [False for _ in range(v)]
    ord = [0 for _ in range(v)]
    low = [float("inf") for _ in range(v)]
    is_articulation = [False for _ in range(v)]
    
    def dfs(v, prev, k):
        if used[v]:
            return
        used[v] = True
        k = k+1
        ord[v] = k
        low[v] = ord[v]
        cnt = 0
        for u in G[v]:
            if not used[u]:
                cnt += 1
                dfs(u, v, k)
                low[v] = min(low[v], low[u])
                if prev >= 0 and ord[v] <= low[u]:
                    is_articulation[v] = True
            elif u != prev:
                low[v] = min(low[v], ord[u])
        if prev == -1 and cnt >= 2:
            is_articulation[v] = True
        
        return k
    
    dfs(0, -1, 0)
    
    for i in range(v):
        if is_articulation[i]:
            print(i)

solve()

Submission status: Accepted

Solution code:
# Python program to find articulation points in an undirected graph

import sys
sys.setrecursionlimit(100000)
from collections import defaultdict

# This class represents an undirected graph
# using adjacency list representation


class Graph:

    def __init__(self, vertices):
        self.V = vertices  # No. of vertices
        self.graph = defaultdict(list)  # default dictionary to store graph
        self.Time = 0

    # function to add an edge to graph
    def addEdge(self, u, v):
        self.graph[u].append(v)
        self.graph[v].append(u)

        '''A recursive function that find articulation points
        using DFS traversal
        u --> The vertex to be visited next
        visited[] --> keeps tract of visited vertices
        disc[] --> Stores discovery times of visited vertices
        parent[] --> Stores parent vertices in DFS tree
        ap[] --> Store articulation points'''

    def APUtil(self, u, visited, ap, parent, low, disc):
        # Count of children in current node
        children = 0

        # Mark the current node as visited and print it
        visited[u] = True

        # Initialize discovery time and low value
        disc[u] = self.Time
        low[u] = self.Time
        self.Time += 1

        # Recur for all the vertices adjacent to this vertex
        for v in self.graph[u]:
            # If v is not visited yet, then make it a child of u
            # in DFS tree and recur for it
            if visited[v] == False:
                parent[v] = u
                children += 1
                self.APUtil(v, visited, ap, parent, low, disc)

                # Check if the subtree rooted with v has a connection to
                # one of the ancestors of u
                low[u] = min(low[u], low[v])

                # u is an articulation point in following cases
                # (1) u is root of DFS tree and has two or more chilren.
                if parent[u] == -1 and children > 1:
                    ap[u] = True

                # (2) If u is not root and low value of one of its child is mor
                # than discovery value of u.
                if parent[u] != -1 and low[v] >= disc[u]:
                    ap[u] = True

                # Update low value of u for parent function calls
            elif v != parent[u]:
                low[u] = min(low[u], disc[v])

    # The function to do DFS traversal. It uses recursive APUtil()
    def AP(self):

        # Mark all the vertices as not visited
        # and Initialize parent and visited,
        # and ap(articulation point) arrays
        visited = [False] * (self.V)
        disc = [float("Inf")] * (self.V)
        low = [float("Inf")] * (self.V)
        parent = [-1] * (self.V)
        ap = [False] * (self.V)  # To store articulation points

        # Call the recursive helper function
        # to find articulation points
        # in DFS tree rooted with vertex 'i'
        for i in range(self.V):
            if visited[i] == False:
                self.APUtil(i, visited, ap, parent, low, disc)
        for index, value in enumerate(ap):
            if value == True:
                print(index)


def main():
    V, E = map(int, input().split())
    G = Graph(V)
    for _ in range(E):
        s, t = map(int, input().split())
        G.addEdge(s, t)

    G.AP()




if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

class LowLink():
    def __init__(self,G):
        self.N = len(G)
        self.G = G
        self.low = [-1] * self.N
        self.ord = [-1] * self.N
    
    def _dfs(self,v,time,p = -1):
        self.ord[v] = self.low[v] = time
        time += 1

        isArticulation = False
        cnt = 0
        for e in self.G[v]:
            if self.low[e] < 0:
                cnt += 1
                self._dfs(e,time,v)
                self.low[v] = min(self.low[v],self.low[e])
                if p != -1 and self.ord[v] <= self.low[e]:
                    isArticulation = True
                if self.ord[v] < self.low[e]:
                    self.bridge.append((v,e))
            elif e != p:
                self.low[v] = min(self.low[v],self.ord[e])
        
        if p == -1 and cnt >= 2:
            isArticulation = True
        if isArticulation:
            self.articulation.append(v) 

    def build(self):
        self.articulation = []
        self.bridge = []
        self._dfs(0,0)
    

def main():
    V,E = map(int,input().split())
    G = [[] for _ in range(V)]
    for _ in range(E):
        a,b = map(int,input().split())
        G[a].append(b)
        G[b].append(a)
    
    lowlink = LowLink(G)
    lowlink.build()
    ans = lowlink.articulation
    ans.sort()
    if ans:
        print('\n'.join(map(str,ans)))
if __name__ == '__main__':
    main()