#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector adj(n, std::vector<bool>(n));
for (int i = 0, u, v; i < m; ++i) {
std::cin >> u >> v;
--u, --v;
adj[u][v] = true;
bool changed = true;
while (changed) {
changed = false;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
if (k != i) {
if (!adj[i][k] and adj[i][j] and adj[j][k] and adj[k][j]) {
adj[i][k] = true;
changed = true;
}
}
}
}
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
ans += adj[i][j];
}
}
std::cout << ans << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |