# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
450447 | mjhmjh1104 | Joker (BOI20_joker) | C++17 | 1393 ms | 9392 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <vector>
#include <utility>
using namespace std;
int uf[200006], sz[200006], ds[200006], y[200];
int _find(int x) {
if (uf[x] == -1) return x;
return _find(uf[x]);
}
int _dist(int x) {
if (uf[x] == -1) return 0;
return ds[x] + _dist(uf[x]);
}
bool _merge(int x, int y) {
int a = _dist(x), b = _dist(y);
x = _find(x), y = _find(y);
if (x != y) {
if (sz[x] > sz[y]) {
uf[y] = x, sz[x] += sz[y];
if ((a + b) % 2 == 0) ds[y]++;
} else {
uf[x] = y, sz[y] += sz[x];
if ((a + b) % 2 == 0) ds[x]++;
}
return true;
}
return false;
}
int n, m, q;
vector<pair<int, int>> edges;
int main() {
scanf("%d%d%d", &n, &m, &q);
for (int i = 0; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
u--, v--;
edges.push_back({ u, v });
}
for (int c = 0; c < 200; c++) {
for (int i = 0; i < n; i++) uf[i] = -1, sz[i] = 1, ds[i] = 0;
int x = -1;
for (int i = 0; i < c; i++) if (!_merge(edges[i].first, edges[i].second) && (_dist(edges[i].first) + _dist(edges[i].second) + 1) % 2) {
x = m;
break;
}
if (x == -1) for (int i = m - 1; i >= c; i--) if (!_merge(edges[i].first, edges[i].second) && (_dist(edges[i].first) + _dist(edges[i].second) + 1) % 2) {
x = i;
break;
}
y[c] = x;
}
for (int i = 0; i < q; i++) {
int l, r;
scanf("%d%d", &l, &r);
l--, r--;
if (r < y[l]) puts("YES");
else puts("NO");
}
}
컴파일 시 표준 에러 (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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |