Problem p02925 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef int ll;

ll mix_player_id(ll l, ll r) {
  if (l > r) {
    swap(l, r);
  }
  return l * 1000 + r;
}

int main(int argc, char *argv[]) {
  ll n;
  cin >> n;
  vector<queue<ll>> players(n);
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < n - 1; j++) {
      ll opp;
      cin >> opp;
      opp--;
      players[i].push(mix_player_id(i, opp));
    }
  }

  vector<ll> found(2000000, -1);

  int days = 0;
  vector<ll> update;
  vector<ll> next_update;
  for (ll i = 0; i < players.size(); i++) {
    update.push_back(i);
  }
  while (true) {
    bool is_finished = true;
    bool progressed = false;
    vector<bool> fought(1000);
    for (ll i : update) {
      if (fought[i])
        continue;
      auto &q = players[i];
      if (q.empty())
        continue;

      auto current_idx = q.front();
      is_finished = false;
      if (found[current_idx] >= 0 && found[current_idx] != i) {
        players[found[current_idx]].pop();
        q.pop();
        progressed = true;
        fought[i] = true;
        fought[found[current_idx]] = true;
        next_update.push_back(i);
        next_update.push_back(found[current_idx]);
        found.at(current_idx) = -1;
      } else {
        found.at(current_idx) = i;
      }
    }
    if (is_finished) {
      break;
    }
    if (!progressed) {
      cout << -1 << endl;
      return 0;
    }
    days++;
    swap(update, next_update);
  }
  cout << days << endl;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef int ll;

ll mix_player_id(ll l, ll r) {
  if (l > r) {
    swap(l, r);
  }
  return l * 1000 + r;
}

int main(int argc, char *argv[]) {
  ll n;
  cin >> n;
  vector<queue<ll>> players(n);
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < n - 1; j++) {
      ll opp;
      cin >> opp;
      opp--;
      players[i].push(mix_player_id(i, opp));
    }
  }

  vector<ll> found(2000000, -1);

  int days = 0;
  vector<ll> update;
  vector<ll> next_update;
  for (ll i = 0; i < players.size(); i++) {
    update.push_back(i);
  }
  while (true) {
    next_update.clear();
    bool is_finished = true;
    bool progressed = false;
    vector<bool> fought(1000);
    for (ll i : update) {
      if (fought[i])
        continue;
      auto &q = players[i];
      if (q.empty())
        continue;

      auto current_idx = q.front();
      is_finished = false;
      if (found[current_idx] >= 0 && found[current_idx] != i) {
        players[found[current_idx]].pop();
        q.pop();
        progressed = true;
        fought[i] = true;
        fought[found[current_idx]] = true;
        next_update.push_back(i);
        next_update.push_back(found[current_idx]);
        found.at(current_idx) = -1;
      } else {
        found.at(current_idx) = i;
      }
    }
    if (is_finished) {
      break;
    }
    if (!progressed) {
      cout << -1 << endl;
      return 0;
    }
    days++;
    swap(update, next_update);
  }
  cout << days << endl;
}