Problem p02367 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
class BRI {
public:
  int N;
  vi used;
  vvi G;
  vp bridge;
  void add_edge(int s, int t) {
    G[s].pb(t);
    G[t].pb(s);
  }
  BRI(int size) {
    N = size;
    G = vvi(N);
  }
  int dfs(int i, int prev, int &n) {
    if (used[i])
      return used[i];
    int m = n;
    used[i] = n++;
    rep(j, G[i].size()) {
      if (prev == G[i][j])
        continue;
      if (used[i] < used[G[i][j]])
        continue;
      int res = dfs(G[i][j], i, n);
      m = min(m, res);
      if (used[i] < res)
        bridge.pb(pii(min(i, G[i][j]), max(i, G[i][j])));
    }
    return m;
  }
  void bri() {
    used = vi(N);
    bridge = vp(0);
    int n = 1;
    rep(i, n) if (!used[i]) dfs(i, -1, n);
    sort(all(bridge));
    rep(i, bridge.size()) cout << bridge[i].first << " " << bridge[i].second
                               << endl;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  BRI bri(n);
  while (m--) {
    int a, b;
    cin >> a >> b;
    bri.add_edge(a, b);
  }
  bri.bri();
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
class BRI {
public:
  int N;
  vi used;
  vvi G;
  vp bridge;
  void add_edge(int s, int t) {
    G[s].pb(t);
    G[t].pb(s);
  }
  BRI(int size) {
    N = size;
    G = vvi(N);
  }
  int dfs(int i, int prev, int &n) {
    if (used[i])
      return used[i];
    int m = n;
    used[i] = n++;
    rep(j, G[i].size()) {
      if (prev == G[i][j])
        continue;
      if (used[i] < used[G[i][j]])
        continue;
      int res = dfs(G[i][j], i, n);
      m = min(m, res);
      if (used[i] < res)
        bridge.pb(pii(min(i, G[i][j]), max(i, G[i][j])));
    }
    return m;
  }
  void bri() {
    used = vi(N);
    bridge = vp(0);
    int n = 1;
    rep(i, N) if (!used[i]) dfs(i, -1, n);
    sort(all(bridge));
    rep(i, bridge.size()) cout << bridge[i].first << " " << bridge[i].second
                               << endl;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  BRI bri(n);
  while (m--) {
    int a, b;
    cin >> a >> b;
    bri.add_edge(a, b);
  }
  bri.bri();
}