GRL_3_A Articulation Points

Calendar Clock iconCalendar Clock icon


Table of contents

# Problem

# Computational complexity


# Solution

// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define rep(n) for(int x = 0; x < n; x++)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1))

using namespace std;

#define MAX_V 10000

vector<Int> graph[MAX_V];
bool used_v[MAX_V],used_e[MAX_V][MAX_V];
Int ord[MAX_V],lowlink[MAX_V];
Int k=0;
vector<Int> aps;

void dfs(Int v, Int parent) {
  used_v[v] = true;
  bool isAp = false;
  Int childCnt = 0;
  for (Int u: graph[v]) {
    if(!used_v[u]) {
      used_e[v][u] = true;
      dfs(u, v);
      lowlink[v] = min(lowlink[v], lowlink[u]);
      isAp |= parent != -1 && lowlink[u] >= ord[v];
    else if(!used_e[u][v]) {
      lowlink[v] = min(lowlink[v], ord[u]);
  isAp |= parent == -1 && childCnt >= 2;
  if (isAp) aps.push_back(v);

Int main(void) {
  Int n, e, u, v;
  cin >> n >> e;
  loop(i,0,e) {
    cin >> u >> v;
  dfs(0, -1);
  sort(aps.begin(), aps.end());
  for (Int v: aps) cout << v << endl;

Remote freelancer. A web and mobile application enginner.
Traveling around the world based on East Asia.
I'm looking forward to your job offers from all over the world!

Offer jobs or contact me!