alexjercan/bugnet huggingface dataset:
Problem p02364 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
#define MV 10000
#define INF 1e9

struct edge {
  int to, cost;
};
vector<edge> G[MV];
bool used[MV];
int V, E;
int d[MV];
int prim() {

  for (int i = 0; i < V; i++) {
    d[i] = INF;
    used[i] = false;
  }
  d[0] = 0;
  used[0] = true;

  for (int i = 0; i < G[0].size(); i++)
    d[G[0][i].to] = G[0][i].cost;

  int num = 0;

  for (int j = 0; j < V; j++) {
    int m = -1;
    for (int i = 0; i < V; i++) {
      if (used[i] == false && (m == -1 || d[m] > d[i]))
        m = i;
    }
    if (m == -1)
      break;
    used[m] = true;
    num += d[m];
    for (int i = 0; i < G[m].size(); i++)
      d[G[m][i].to] = min(d[G[m][i].to], G[m][i].cost);
  }
  return num;
}

int main() {
  int first;
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    int f, t;
    edge e;
    cin >> f >> e.to >> e.cost;
    G[f].push_back(e);
    /*
      G[f]??????f????????§????????????????´???????????????????
     */
    t = e.to;

    e.to = f;
    G[t].push_back(e);
  }

  int fl = prim();
  cout << fl << endl;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
#define MV 10000
#define INF 1e9

struct edge {
  int to, cost;
};
vector<edge> G[MV];
bool used[MV];
int V, E;
int d[MV];
int prim() {

  for (int i = 0; i < V; i++) {
    d[i] = INF;
    used[i] = false;
  }
  d[0] = 0;
  used[0] = true;

  for (int i = 0; i < G[0].size(); i++)
    d[G[0][i].to] = G[0][i].cost;

  int num = 0;

  for (int j = 0; j < V; j++) {
    int m = -1;
    for (int i = 0; i < V; i++) {
      if (used[i] == false && (m == -1 || d[m] > d[i]))
        m = i;
    }
    /*if (m == -1)
      break;*/
    used[m] = true;
    num += d[m];
    for (int i = 0; i < G[m].size(); i++)
      d[G[m][i].to] = min(d[G[m][i].to], G[m][i].cost);
  }
  return num;
}

int main() {
  int first;
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    int f, t;
    edge e;
    cin >> f >> e.to >> e.cost;
    G[f].push_back(e);
    /*
      G[f]??????f????????§????????????????´???????????????????
     */
    t = e.to;

    e.to = f;
    G[t].push_back(e);
  }

  int fl = prim();
  cout << fl << endl;
}
Problem p02364 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000

using namespace std;

typedef long long int lli;
typedef pair<int, int> P;

struct edge {
  int to, cost;
};

int V, E;
vector<edge> e[10000];
int mincost[10000];
bool used[10000];

int main(void) {
  cin >> V >> E;

  for (int i = 0; i < V; i++) {
    mincost[i] = INF;
    used[i] = false;
  }

  for (int i = 0; i < E; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edge d;
    d.to = b;
    d.cost = c;
    e[a].push_back(d);
    d.to = a;
    e[b].push_back(d);
  }

  mincost[0] = 0;
  long long int res = 0;

  while (true) {
    int v = -1;
    for (int u = 0; u < V; u++) {
      if (!used[u] && (v == -1 || mincost[u] < mincost[v]))
        v = u;
    }

    if (v == -1)
      break;
    used[v] = true;
    res += mincost[v];

    for (int u = 0; u < e[v].size(); u++) {
      mincost[e[v][u].to] = min(mincost[e[v][u].to], e[v][u].cost);
    }
  }
  cout << res << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 10000000

using namespace std;

typedef long long int lli;
typedef pair<int, int> P;

struct edge {
  int to, cost;
};

int cost[10000][10000];
int mincost[10000];
bool used[10000];
int V;
int E;

class Union_find {
private:
  vector<int> par;
  vector<int> rank;
  int n;

public:
  Union_find(int a) {
    n = a;
    for (int i = 0; i < n; i++) {
      par.push_back(i);
      rank.push_back(0);
    }
  }

  int find(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = find(par[x]);
    }
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;

    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y])
        rank[x]++;
    }
  }

  bool same(int x, int y) { return find(x) == find(y); }
};

int main(void) {

  cin >> V >> E;

  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      cost[i][j] = INF;
    }
  }

  for (int i = 0; i < E; i++) {
    int a, b;
    cin >> a >> b;
    cin >> cost[a][b];
    cost[b][a] = cost[a][b];
  }

  for (int i = 0; i < V; i++) {
    mincost[i] = INF;
    used[i] = false;
  }

  mincost[0] = 0;
  int res = 0;

  while (true) {
    int v = -1;
    for (int u = 0; u < V; u++) {
      if (!used[u] && (v == -1 || mincost[u] < mincost[v]))
        v = u;
    }

    if (v == -1)
      break;
    used[v] = true;
    res += mincost[v];

    for (int u = 0; u < V; u++) {
      mincost[u] = min(mincost[u], cost[v][u]);
    }
  }
  cout << res << endl;
  return 0;
}
Problem p02364 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
#define MV 10000
#define INF 1e9

struct edge {
  int to, cost;
};
vector<edge> G[MV];
bool used[MV];
int V, E;
int d[MV];
int prim() {

  for (int i = 0; i < V; i++) {
    d[i] = INF;
    used[i] = false;
  }
  d[0] = 0;
  used[0] = true;

  for (int i = 0; i < G[0].size(); i++)
    d[G[0][i].to] = G[0][i].cost;

  int num = 0;

  while (true) {
    int m = -1;
    for (int i = 0; i < V; i++) {
      if (used[i] == false && (m == -1 || d[m] > d[i]))
        m = i;
    }
    if (m == -1)
      break;
    used[m] = true;
    num += d[m];
    for (int i = 0; i < G[m].size(); i++)
      d[G[m][i].to] = min(d[G[m][i].to], G[m][i].cost);
  }
  return num;
}

int main() {
  int first;
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    int f, t;
    edge e;
    cin >> f >> e.to >> e.cost;
    G[f].push_back(e);
    /*
      G[f]??????f????????§????????????????´???????????????????
     */
    t = e.to;

    e.to = f;
    G[t].push_back(e);
  }

  int fl = prim();
  cout << fl << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
#define MV 100000
#define INF 1e9

struct edge {
  int to, cost;
};
vector<edge> G[MV];
bool used[1000];
int V, E;
int d[MV];
int prim() {

  for (int i = 0; i < V; i++) {
    d[i] = INF;
    used[i] = false;
  }
  d[0] = 0;
  used[0] = true;

  for (int i = 0; i < G[0].size(); i++)
    d[G[0][i].to] = G[0][i].cost;

  int num = 0;

  while (true) {
    int m = -1;
    for (int i = 0; i < V; i++) {
      if (used[i] == false && (m == -1 || d[m] > d[i]))
        m = i;
    }
    if (m == -1)
      break;
    used[m] = true;
    num += d[m];
    for (int i = 0; i < G[m].size(); i++)
      d[G[m][i].to] = min(d[G[m][i].to], G[m][i].cost);
  }
  return num;
}

int main() {
  int first;
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    int f, t;
    edge e;
    cin >> f >> e.to >> e.cost;
    G[f].push_back(e);
    /*
      G[f]??????f????????§????????????????´???????????????????
     */
    t = e.to;

    e.to = f;
    G[t].push_back(e);
  }

  int fl = prim();
  cout << fl << endl;
}
Problem p02366 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)

int const INF = 1 << 29;

typedef vector<int> edges;
typedef vector<edges> graph;

namespace articulation {

int const MaxNum = 100000;

int prenum[MaxNum];
int lowest[MaxNum];
int parent[MaxNum];
int timer;
int V;

bool visited[MaxNum];
graph g;

void dfs(int curr) {
  prenum[curr] = timer;
  lowest[curr] = timer;
  timer++;

  visited[curr] = 1;

  rep(i, g[curr].size()) {
    int next = g[curr][i];
    if (!visited[next]) {
      parent[next] = curr;
      dfs(next);
      lowest[curr] = min(lowest[curr], lowest[next]);
    } else if (next != curr) {
      lowest[curr] = min(lowest[curr], prenum[next]);
    }
  }
}

vector<int> doit(int V_) {
  V = V_;
  rep(i, V) { visited[i] = 0; }
  timer = 1;
  dfs(0);

  vector<int> ret;
  int cnt = 0;
  rep(i, V) {
    if (i && parent[i] == 0) {
      cnt++;
    }
    if (parent[i] > 0 && lowest[i] >= prenum[parent[i]]) {
      ret.push_back(parent[i]);
    }
  }
  if (cnt >= 2) {
    ret.push_back(0);
  }
  sort(ret.begin(), ret.end());
  ret.erase(unique(ret.begin(), ret.end()), ret.end());
  return ret;
}

} // namespace articulation

int main() {

  using namespace articulation;

  int N, M;
  cin >> N >> M;
  g.resize(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<int> arts = doit(N);

  rep(i, arts.size()) { cout << arts[i] << endl; }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (int i = a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)

int const INF = 1 << 29;

typedef vector<int> edges;
typedef vector<edges> graph;

namespace articulation {

int const MaxNum = 1000;

int prenum[MaxNum];
int lowest[MaxNum];
int parent[MaxNum];
int timer;
int V;

bool visited[MaxNum];
graph g;

void dfs(int curr) {
  prenum[curr] = timer;
  lowest[curr] = timer;
  timer++;

  visited[curr] = 1;

  rep(i, g[curr].size()) {
    int next = g[curr][i];
    if (!visited[next]) {
      parent[next] = curr;
      dfs(next);
      lowest[curr] = min(lowest[curr], lowest[next]);
    } else if (next != curr) {
      lowest[curr] = min(lowest[curr], prenum[next]);
    }
  }
}

vector<int> doit(int V_) {
  V = V_;
  rep(i, V) { visited[i] = 0; }
  timer = 1;
  dfs(0);

  vector<int> ret;
  int cnt = 0;
  rep(i, V) {
    if (i && parent[i] == 0) {
      cnt++;
    }
    if (parent[i] > 0 && lowest[i] >= prenum[parent[i]]) {
      ret.push_back(parent[i]);
    }
  }
  if (cnt >= 2) {
    ret.push_back(0);
  }
  sort(ret.begin(), ret.end());
  ret.erase(unique(ret.begin(), ret.end()), ret.end());
  return ret;
}

} // namespace articulation

int main() {

  using namespace articulation;

  int N, M;
  cin >> N >> M;
  g.resize(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<int> arts = doit(N);

  rep(i, arts.size()) { cout << arts[i] << endl; }

  return 0;
}
Problem p02366 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#pragma warning(disable : 4996)

int N, M, A[1 << 17], B[1 << 17], low[1 << 17], pre[1 << 17], cnts = 0;
vector<int> G[1 << 17], Articulation;

void dfs(int pos, int prevs) {
  cnts++;
  pre[pos] = cnts;
  low[pos] = cnts;

  bool flag = false;
  int deg = 0;
  for (int i = 0; i < G[pos].size(); i++) {
    if (pre[G[pos][i]] == 0) {
      dfs(G[pos][i], pos);
      deg++;
      low[pos] = min(low[pos], low[G[pos][i]]);
      if (pos >= 1 && pre[pos] <= low[G[pos][i]]) {
        flag = true;
      }
    } else {
      if (pos != prevs)
        low[pos] = min(low[pos], pre[G[pos][i]]);
    }
  }
  if (pos == 0 && deg >= 2)
    flag = true;
  if (flag == true)
    Articulation.push_back(pos);
}

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; i++) {
    scanf("%d%d", &A[i], &B[i]);
    G[A[i]].push_back(B[i]);
    G[B[i]].push_back(A[i]);
  }
  dfs(0, -1);
  sort(Articulation.begin(), Articulation.end());
  for (int i : Articulation)
    printf("%d\\n", i);
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define MAX_N 177777
vector<int> X[MAX_N];
int used[MAX_N];
int N, M, A, B;
queue<int> Q;
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    X[A].push_back(B);
    X[B].push_back(A);
  }
  if (N == 1) {
    return 0;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      used[j] = 0;
    }
    if (i >= 1) {
      Q.push(0);
      used[0] = 1;
    } else {
      Q.push(1);
      used[1] = 1;
    }
    int cnt = 1;
    while (!Q.empty()) {
      int a1 = Q.front();
      Q.pop();
      for (int j = 0; j < X[a1].size(); j++) {
        if (used[X[a1][j]] == 0 && X[a1][j] != i) {
          used[X[a1][j]] = 1;
          Q.push(X[a1][j]);
          cnt++;
        }
      }
    }
    if (cnt != N - 1) {
      cout << i << endl;
    }
  }
  return 0;
}
Problem p02366 (C++) — buggy submission, verdict: Time Limit Exceeded

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_B&lang=jp
// hos?????????????????????????????????
// lowlink????¨??????????????????§??????
// lowlink????¨??????????????????§????????????????????¢?????¨?????????????????????????????§
// http://kagamiz.hatenablog.com/entry/2013/10/05/005213??????????????????
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
vector<int> G[100000];
vector<P> bridge;
vector<int> articulation;
int ord[100000], low[100000];
bool vis[100000];
int v, e, s, t, k;
void dfs(int v, int p, int &k) {
  vis[v] = true;
  ord[v] = k++;
  low[v] = ord[v];
  bool isArticulation = false;
  int ct = 0;
  for (int i = 0; i < G[v].size(); i++) {
    if (!vis[G[v][i]]) {
      ct++;
      dfs(G[v][i], v, k);
      low[v] = min(low[v], low[G[v][i]]);
      if (~p && ord[v] <= low[G[v][i]])
        isArticulation = true;
      if (ord[v] < low[G[v][i]])
        bridge.push_back(P(min(v, G[v][i]), max(v, G[v][i])));
    } else if (G[v][i] != p) {
      low[v] = min(low[v], ord[G[v][i]]);
    }
  }
  if (p == -1 && ct > 1)
    isArticulation = true;
  if (isArticulation)
    articulation.push_back(v);
}
int main() {
  scanf("%d%d", &v, &e);
  for (int i = 0; i < e; i++) {
    scanf("%d%d", &s, &t);
    G[s].push_back(t);
    G[t].push_back(s);
  }
  if (v == 1) {
  } else {
    k = 0;
    for (int i = 0; i < v; i++) {
      if (!vis[i])
        dfs(i, -1, k);
    }
    sort(articulation.begin(), articulation.end());
    for (int i = 0; i < articulation.size(); i++)
      printf("%d\\n", articulation[i]);
  }
}

Error: TLE

Fixed submission:

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A&lang=jp
// ??±???????????§???????????????????????£???????????¢?´¢?????????????????????????????£????????¢????????¨???????????¨?????????
// ???????????????O(v^2)
#include <bits/stdc++.h>
using namespace std;
int graph[100000];
vector<int> edge[100000];
vector<int> stock;
int v, e, s, t;
void dfs(int now) {
  graph[now] = 1;
  stock.push_back(now);
  for (int i = 0; i < edge[now].size(); i++) {
    if (graph[edge[now][i]] == 0) {
      dfs(edge[now][i]);
    }
  }
}
int main() {
  scanf("%d%d", &v, &e);
  for (int i = 0; i < e; i++) {
    scanf("%d%d", &s, &t);
    edge[s].push_back(t);
    edge[t].push_back(s);
  }
  if (v == 1) {
  } else {
    for (int i = 0; i < v; i++) {
      memset(graph, 0, sizeof(graph));
      graph[i] = 1;
      stock = vector<int>();
      stock.push_back(i);
      dfs(edge[i][0]);
      if (stock.size() != v)
        printf("%d\\n", i);
    }
  }
}
Problem p02366 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <set>
#include <vector>
using namespace std;

const int MAX_V = 100000;

vector<int> G[MAX_V];
int vertex, edge;
bool visited[MAX_V];
int prenum[MAX_V], parent[MAX_V], lowest[MAX_V];
int timer;
set<int> ap;

void dfs(int current, int prev) {
  prenum[current] = lowest[current] = timer;
  timer++;

  visited[current] = true;

  int next;
  for (auto i = 0; i < G[current].size(); i++) {
    next = G[current][i];
    if (!visited[next]) {
      parent[next] = current;
      dfs(next, current);
      lowest[current] = min(lowest[current], lowest[next]);
    } else if (next != prev) {
      lowest[current] = min(lowest[current], prenum[next]);
    }
  }
}

void ArticulationPoints(void) {
  timer = 1;
  dfs(0, -1);

  int np = 0;
  for (int i = 1; i < vertex; i++) {
    int p = parent[i];
    if (p == 0)
      np++;
    else if (prenum[p] <= lowest[i])
      ap.insert(p);
  }
  if (np > 1)
    ap.insert(0);
}

int main(void) {
  cin >> vertex >> edge;
  for (int i = 0; i < vertex; i++) {
    visited[i] = false;
  }

  int s, t;
  for (int i = 0; i < edge; i++) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  ArticulationPoints();

  for (auto it = ap.begin(); it != ap.end(); it++) {
    cout << *it << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <set>
#include <vector>
using namespace std;

const int MAX_V = 100000;

vector<int> G[MAX_V];
int vertex, edge;
bool visited[MAX_V];
int prenum[MAX_V], parent[MAX_V], lowest[MAX_V];
int timer;
set<int> ap;

void dfs(int current, int prev) {
  prenum[current] = lowest[current] = timer;
  timer++;

  visited[current] = true;

  int next;
  for (auto i = 0; i < G[current].size(); i++) {
    next = G[current][i];
    if (!visited[next]) {
      parent[next] = current;
      dfs(next, current);
      lowest[current] = min(lowest[current], lowest[next]);
    } else if (next != prev) {
      lowest[current] = min(lowest[current], prenum[next]);
    }
  }
}

void ArticulationPoints(void) {
  timer = 1;
  dfs(0, -1);

  int np = 0;
  for (int i = 1; i < vertex; i++) {
    int p = parent[i];
    if (p == 0)
      np++;
    else if (prenum[p] <= lowest[i])
      ap.insert(p);
  }
  if (np > 1)
    ap.insert(0);
}

int main(void) {
  cin >> vertex >> edge;
  for (int i = 0; i < vertex; i++) {
    visited[i] = false;
  }

  int s, t;
  for (int i = 0; i < vertex; i++) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  ArticulationPoints();

  for (auto it = ap.begin(); it != ap.end(); it++) {
    cout << *it << endl;
  }

  return 0;
}
Problem p02366 (C++) — buggy submission, verdict: Runtime Error

/*
??¢??????
lowlink
*/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
const int MAX_V = 100000;
vector<int> G[MAX_V];
int ord[MAX_V], low[MAX_V];
int I;
int sum[MAX_V];
vector<int> arts;
void dfs(int v, int p) {
  ord[v] = ++I;
  low[v] = ord[v];
  sum[v] = 1;
  int mx = 0, c = 0;
  for (int u : G[v])
    if (u != p) {
      if (ord[u])
        chmin(low[v], ord[u]);
      else {
        dfs(u, v);
        c++;
        sum[v] += sum[u];
        chmin(low[v], low[u]);
        chmax(mx, low[u]);
      }
    }
  if (p < 0) {
    if (c > 1)
      arts.pb(v);
  } else {
    //		cout<<"v="<<v<<"  mx="<<mx<<endl;
    if (ord[v] <= mx)
      arts.pb(v);
  }
}
void arti(int N) { rep(i, N) if (ord[i] == 0) dfs(i, -1); }
int main() {
  int N, M;
  cin >> N >> M;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    G[a].pb(b);
    G[b].pb(a);
  }
  arti(N);
  sort(all(arts));
  for (int a : arts)
    cout << a << endl;
}

Error: 0

Fixed submission:

/*
??¢??????
lowlink
*/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
const int MAX_V = 100;
vector<int> G[MAX_V];
int ord[MAX_V], low[MAX_V];
int I;
int sum[MAX_V];
vector<int> arts;
void dfs(int v, int p) {
  ord[v] = ++I;
  low[v] = ord[v];
  sum[v] = 1;
  int mx = 0, c = 0;
  for (int u : G[v])
    if (u != p) {
      if (ord[u])
        chmin(low[v], ord[u]);
      else {
        dfs(u, v);
        c++;
        sum[v] += sum[u];
        chmin(low[v], low[u]);
        chmax(mx, low[u]);
      }
    }
  if (p < 0) {
    if (c > 1)
      arts.pb(v);
  } else {
    //		cout<<"v="<<v<<"  mx="<<mx<<endl;
    if (ord[v] <= mx)
      arts.pb(v);
  }
}
void arti(int N) { rep(i, N) if (ord[i] == 0) dfs(i, -1); }
int main() {
  int N, M;
  cin >> N >> M;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    G[a].pb(b);
    G[b].pb(a);
  }
  arti(N);
  sort(all(arts));
  for (int a : arts)
    cout << a << endl;
}
Problem p02366 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>
#include <vector>
using namespace std;

void DFS(int idx, vector<vector<int>> &node, vector<int> &prenum,
         vector<int> &lowest, vector<int> &parent, int &num) {
  // cout << "idx = " << idx << endl;
  prenum[idx] = num++;
  lowest[idx] = prenum[idx];
  for (int i = 0; i < node[idx].size(); i++) {
    if (node[idx][i] == parent[idx])
      continue;
    int lowest_tmp;
    if (node[idx][i] != 0 && parent[node[idx][i]] == -1) {
      parent[node[idx][i]] = idx;
      DFS(node[idx][i], node, prenum, lowest, parent, num);
      lowest_tmp = lowest[node[idx][i]];
    } else {
      lowest_tmp = prenum[node[idx][i]];
    }
    lowest[idx] = min(lowest[idx], lowest_tmp);
  }
}

void AP(vector<vector<int>> &node, set<int> &ans) {
  int size = node.size();
  vector<int> prenum(size, 0);
  vector<int> lowest(size, 0);
  vector<int> parent(size, -1);
  int num = 1;
  DFS(0, node, prenum, lowest, parent, num);
  int n_zero = 0;
  for (int i = 1; i < size; i++) {
    if (parent[i] == 0)
      n_zero++;
  }
  if (n_zero >= 2)
    ans.insert(0);
  for (int i = 1; i < size; i++) {
    if (lowest[i] >= prenum[parent[i]] && parent[i] != 0) {
      ans.insert(parent[i]);
    }
  }
  // for (int i = 0; i < size; i++) {
  //     cout << i << " : " << prenum[i] << " " << lowest[i] << " " << parent[i]
  //     << endl;
  // }
}

int main() {
  int V, E;
  cin >> V >> E;
  vector<vector<int>> node(V);
  for (int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    node[s].push_back(t);
    node[t].push_back(s);
  }

  // for (int i = 0; i < V; i++) {
  //     for (int j = 0; j < node[i].size(); j++) {
  //         cout << node[i][j] << " ";
  //     }
  //     cout << endl;
  // }

  set<int> ans;
  AP(node, ans);
  for (auto it = ans.begin(); it != ans.end(); it++) {
    cout << *it << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
bool search_(int s, int t, vector<vector<int>> &node, vector<int> &memo,
             vector<int> &memo2) {
  memo2[s] = 1;
  if (memo[s])
    return false;
  memo[s] = 1;
  if (s == t)
    return true;
  for (int i = 0, len = node[s].size(); i < len; i++) {
    if (search_(node[s][i], t, node, memo, memo2))
      return true;
  }
  return false;
}
bool is_AP(int obj, vector<vector<int>> &node) {
  int s = node[obj][0];
  vector<int> memo2(node.size(), 0);
  for (int j = 1, len = node[obj].size(); j < len; j++) {
    if (memo2[node[obj][j]])
      continue;
    ;
    vector<int> memo(node.size(), 0);
    memo[obj] = 1;
    if (!search_(s, node[obj][j], node, memo, memo2))
      return true;
  }
  return false;
}

int main() {
  int V, E;
  cin >> V >> E;
  vector<vector<int>> node(V);
  for (int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    node[s].push_back(t);
    node[t].push_back(s);
  }
  vector<int> ans;
  for (int i = 0; i < V; i++) {
    if (node[i].size() < 2)
      continue;
    if (is_AP(i, node))
      ans.push_back(i);
  }
  for (int i = 0, s = ans.size(); i < s; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}