This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
const int N = 51;
int gr[N][N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
int ans = 0;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--, y--;
if (!gr[x][y]) {
gr[x][y] = true;
ans++;
bool work = true;
while (work) {
work = false;
for (int x = 0; x < n; x++) {
for (int y = 0; y < n; y++) {
for (int z = 0; z < n; z++) {
if (z != x && gr[x][y] && gr[y][z] && gr[z][y] && !gr[x][z]) {
gr[x][z] = true;
work = true;
ans++;
}
}
}
}
}
}
cout << ans << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |