Submission #1257007

#TimeUsernameProblemLanguageResultExecution timeMemory
1257007LucaLucaMMaking Friends on Joitter is Fun (JOI20_joitter2)C++20
1 / 100
5091 ms584 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>

using ll = long long;
#define debug(x) #x << " = " << x << '\n'

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  int n, m;
  std::cin >> n >> m;

  std::vector<std::vector<bool>> g(n, std::vector<bool>(n, false));

  int answer = 0;

  while (m--) {
    int u, v;
    std::cin >> u >> v;
    u--, v--;
    if (g[u][v]) {
      std::cout << answer << '\n';
      continue;
    }
    g[u][v] = true;
    answer++;
    bool repeat = true;
    while (repeat) {
      repeat = false;
      for (int x = 0; x < n; x++) {
        for (int y = 0; y < n; y++) {
          for (int z = 0; z < n; z++) {
            if (x != z && g[x][y] && g[y][z] && g[z][y] && !g[x][z]) {
              g[x][z] = true;
              repeat = true;
              answer++;
            }
          }
        }
      }
    }
    std::cout << answer << '\n';
  }

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...