# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1162378 | blackslex | 조이터에서 친구를 만드는건 재밌어 (JOI20_joitter2) | C++20 | 0 ms | 328 KiB |
#include<bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, m, x, y, ans;
vector<int> v[N];
bool f[N][N];
void add (int x, int y) {
if (f[x][y]) return;
f[x][y] = 1;
ans++;
for (auto &e: v[y]) {
if (x != e && !f[x][e]) 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(i, y);
if (f[i][y] && !f[i][x]) add(i, x);
}
}
v[x].emplace_back(y);
v[y].emplace_back(x);
}
}
int main() {
scanf("%d %d", &n, &m);
while (m--) {
scanf("%d %d", &x, &y);
if (!f[x][y]) add(x, y);
printf("%d\n", ans);
}
}
컴파일 시 표준 에러 (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... |