# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1162370 | blackslex | 조이터에서 친구를 만드는건 재밌어 (JOI20_joitter2) | C++20 | 0 ms | 528 KiB |
#include<bits/stdc++.h>
using namespace std;
int n, m, x, y;
int main() {
scanf("%d %d", &n, &m);
vector<vector<bool>> f(n + 5, vector<bool>(n + 5));
vector<vector<int>> v(n + 5, vector<int>());
int ans = 0;
auto add = [&] (auto &&add, int x, int y) -> void {
if (f[x][y]) return;
f[x][y] = 1;
ans++;
for (auto &e: v[y]) {
if (x != e && !f[x][e]) add(add, x, e);
}
if (f[y][x]) {
for (int i = 1; i <= n; i++) {
if (i != x && i != y) {
if (f[i][x] && !f[i][y]) add(add, i, y);
if (f[i][y] && !f[i][x]) add(add, i, x);
}
}
v[x].emplace_back(y);
v[y].emplace_back(x);
}
};
while (m--) {
scanf("%d %d", &x, &y);
if (!f[x][y]) add(add, x, y);
printf("%d\n", ans);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |