Problem p03647 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <math.h>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <stdlib.h>
#include <streambuf>
#include <string.h>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MAX 100000000000000000
#define MOD 1000000007
#define files freopen("OUTPUT.TXT", "r", stdin);
#define PI 3.141592653589793238462
#define INF 1000000000
using namespace std;
int n, m, i, x, y, z;
bool u[111];
vector<int> g[111];
bool tf;
void dfs(int i, int ro) {
  ro++;
  if (i == n && ro <= 3) {
    cout << "POSSIBLE";
    tf = true;
  } else if (ro > 2) {
    return;
  }
  u[i] = true;
  z++;
  for (int j = 0; j < g[i].size(); j++) {
    if (!u[g[i][j]]) {
      dfs(g[i][j], ro);
    }
  }
  return;
}
int main() {
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 0);
  if (tf == false) {
    cout << "IMPOSSIBLE";
  }
  system("pause");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <math.h>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <stdlib.h>
#include <streambuf>
#include <string.h>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MAX 100000000000000000
#define MOD 1000000007
#define files freopen("OUTPUT.TXT", "r", stdin);
#define PI 3.141592653589793238462
#define INF 1000000000
using namespace std;
int n, m, i, x, y, z;
bool u[200005];
vector<int> g[200005];
bool tf;
void dfs(int i, int ro) {
  ro++;
  if (i == n && ro <= 3) {
    cout << "POSSIBLE";
    tf = true;
  } else if (ro > 2) {
    return;
  }
  u[i] = true;
  z++;
  for (int j = 0; j < g[i].size(); j++) {
    if (!u[g[i][j]]) {
      dfs(g[i][j], ro);
    }
  }
  return;
}
int main() {
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs(1, 0);
  if (tf == false) {
    cout << "IMPOSSIBLE";
  }
  system("pause");
  return 0;
}