Problem p02580 (C++) — buggy submission, verdict: Runtime Error

/*                                  / \\ (Hello)//JSM//*/
/*                                 /*****\\ */
/*     Jai Shree Mataji           /       \\ |\\| |_| $ |-| K */
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string.h>
#include <vector>
using namespace std;
#define ll long long int
#define ld long double
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define YY cout << "YES"
#define NN cout << "NO"
#define EE cout << "\\n"
#define ee cout << "\\n"
#define ne cout << "-1"
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define mkt make_tuple
#define sall(v) sort(v.begin(), v.end())
#define all(v) v.begin(), v.end()
#define rall(v) reverse(v.begin(), v.end())
#define fo(i, n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vll vector<pair<ll, ll>>
#define mpl map<ll, ll>
#define pr pair<ll, ll>
#define tpl tuple<ll, ll, ll>
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
ll soltn(ll x, ll n) {
  if (x >= 0)
    return x % n;
  else
    return n + x % n;
}
ll pd(ll x, ll y) {
  if (x % y == 0)
    return x / y;
  else
    return x / y + 1;
}
ll coda(ll n, ll d) {
  ll count = 0;
  while (n != 0) {
    if (n % 10 == d)
      count++;
    n /= 10;
  }
  return count;
}
ll pow1(ll n, ll p) {
  if (p == 0)
    return 1;
  ll x = pow1(n, p / 2);
  x = (x * x) % MOD;
  if (p % 2 == 0)
    return x;
  else
    return (x * n) % MOD;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll t = 1;

  //	   cin>>t;
  while (t--) {
    // jai shree mataji
    /*
    3 3 4
    3 3
    3 1
    1 1
    1 2*/
    ll n, m, M;
    cin >> n >> m >> M;
    mpl X;
    mpl Y;
    ll a[M], b[M];
    map<pair<ll, ll>, ll> K;
    ll mx = 0, my = 0;
    fo(i, M) {
      cin >> a[i] >> b[i];
      K[{a[i], b[i]}] = 1;
      X[b[i]]++;
      Y[a[i]]++;
      mx = max(mx, X[b[i]]);
      my = max(my, Y[a[i]]);
    }
    ll ans = mx + my;
    vl v1;
    vl v2;
    fo(i, n) {
      if (Y[i + 1] == my) {
        v1.pb(i + 1);
      }
    }
    fo(i, m) {
      if (X[i + 1] == mx) {
        v2.pb(i + 1);
      }
    }
    fo(i, v1.size()) {
      fo(j, v2.size()) {
        if (K[{v1[i], v2[j]}] == 0) {
          cout << ans;
          ee;
          return 0;
          //		break;
        }
      }
    }
    ans--;
    cout << ans;
    ee;
  }
  return 0;
}


Error: 0

Fixed submission:

/*                                  / \\ (Hello)//JSM//*/
/*                                 /*****\\ */
/*     Jai Shree Mataji           /       \\ |\\| |_| $ |-| K */
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string.h>
#include <vector>
using namespace std;
#define ll long long int
#define ld long double
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define YY cout << "YES"
#define NN cout << "NO"
#define EE cout << "\\n"
#define ee cout << "\\n"
#define ne cout << "-1"
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define mkt make_tuple
#define sall(v) sort(v.begin(), v.end())
#define all(v) v.begin(), v.end()
#define rall(v) reverse(v.begin(), v.end())
#define fo(i, n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vll vector<pair<ll, ll>>
#define mpl map<ll, ll>
#define pr pair<ll, ll>
#define tpl tuple<ll, ll, ll>
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
ll soltn(ll x, ll n) {
  if (x >= 0)
    return x % n;
  else
    return n + x % n;
}
ll pd(ll x, ll y) {
  if (x % y == 0)
    return x / y;
  else
    return x / y + 1;
}
ll coda(ll n, ll d) {
  ll count = 0;
  while (n != 0) {
    if (n % 10 == d)
      count++;
    n /= 10;
  }
  return count;
}
ll pow1(ll n, ll p) {
  if (p == 0)
    return 1;
  ll x = pow1(n, p / 2);
  x = (x * x) % MOD;
  if (p % 2 == 0)
    return x;
  else
    return (x * n) % MOD;
}
/*vl v[300009];
ll vis[300009];
ll d;
ll ma;
ll ext;
ll up=0;
mpl M;
void dfs(ll node,ll distance)
{
        if(vis[node]==1)
        return;
        if(ma<=distance)
        {
                ma=distance;
                ext=node;
        }
        if(up==1)
        {
                if(distance==ma)
                M[node]=1;
        }
        vis[node]=1;
        for(ll i=0;i<v[node].size();i++)
        {
                ll child=v[node][i];
                dfs(child,distance+1);
        }
}*/
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll t = 1;

  //	   cin>>t;
  while (t--) {
    // jai shree mataji
    /*
    3 3 4
    3 3
    3 1
    1 1
    1 2*/
    ll n, m, M;
    cin >> n >> m >> M;
    mpl X;
    mpl Y;
    ll a[M], b[M];
    map<pair<ll, ll>, ll> K;
    ll mx = 0, my = 0;
    fo(i, M) {
      ll x, y;
      cin >> x >> y;
      a[i] = x;
      b[i] = y;
      K[{x, y}] = 1;
      X[y]++;
      Y[x]++;
      mx = max(mx, X[y]);
      my = max(my, Y[x]);
    }
    ll ans = mx + my;
    vl v1;
    vl v2;
    fo(i, n) {
      if (Y[a[i]] == my) {
        v1.pb(a[i]);
        Y[a[i]] = 0;
      }
    }
    fo(i, m) {
      if (X[b[i]] == mx) {
        v2.pb(b[i]);
        X[b[i]] = 0;
      }
    }
    fo(i, v1.size()) {
      fo(j, v2.size()) {
        if (K[{v1[i], v2[j]}] == 0) {
          cout << ans;
          ee;
          return 0;
          //		break;
        }
      }
    }
    ans--;
    cout << ans;
    ee;
  }
  return 0;
}