Problem p03203 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod = 10007;
const llint big = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U> bool mineq(T &a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U> bool maxeq(T &a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
llint gcd(llint a, llint b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
llint lcm(llint a, llint b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); }
template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); }
template <class T> llint LBI(vector<T> &ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> llint UBI(vector<T> &ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W, i, n;
  cin >> H >> W >> n;
  vector<vector<int>> zyama(W + 2);
  for (i = 1; i <= H; i++) {
    zyama[W + 1].pub(i);
  }
  for (i = 1; i <= W; i++) {
    zyama[i].pub(H + 1);
  }
  for (i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    zyama[x].pub(y);
  }
  vector<bool> tka(H + 5);
  tka[1] = 1;
  int sta = 1;
  for (int i = 1; i <= W; i++) {
    for (auto it : zyama[i + 1]) {
      if (tka[it]) {
        cout << i << endl;
        return 0;
      }
    }
    if (find(zyama[i + 1].begin(), zyama[i + 1].end(), sta + 1) ==
        zyama[i + 1].end()) {
      tka[sta + 1] = 1;
      sta++;
    }
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod = 10007;
const llint big = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U> bool mineq(T &a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U> bool maxeq(T &a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
llint gcd(llint a, llint b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
llint lcm(llint a, llint b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); }
template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); }
template <class T> llint LBI(vector<T> &ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> llint UBI(vector<T> &ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W, i, n;
  cin >> W >> H >> n;
  vector<vector<int>> zyama(W + 2);
  for (i = 1; i <= H; i++) {
    zyama[W + 1].pub(i);
  }
  for (i = 1; i <= W; i++) {
    zyama[i].pub(H + 1);
  }
  for (i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    zyama[x].pub(y);
  }
  vector<bool> tka(H + 5);
  tka[1] = 1;
  int sta = 1;
  for (int i = 1; i <= W; i++) {
    for (auto it : zyama[i + 1]) {
      if (tka[it]) {
        cout << i << endl;
        return 0;
      }
    }
    if (find(zyama[i + 1].begin(), zyama[i + 1].end(), sta + 1) ==
        zyama[i + 1].end()) {
      tka[sta + 1] = 1;
      sta++;
    }
  }

  return 0;
}