# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
765253 | 2023-06-24T09:59:31 Z | oyber | Joker (BOI20_joker) | C++14 | 58 ms | 3644 KB |
#include <cstdio> #include <vector> #include <algorithm> #include <functional> using namespace std; vector<int> u; vector<int> s; vector<int> p; int find(int n) { if (u[n] == n) return n; return find(u[n]); } int parity(int n) { if (u[n] == n) return 0; return parity(u[n])^p[n]; } void unite(int a, int b) { int ap = find(a); int bp = find(b); if (s[bp] > s[ap]) { swap(a, b); swap(ap, bp); } u[bp] = ap; s[ap] += s[bp]; if (parity(a) == parity(b)) { p[bp] = 1; } } int main() { int n, m, qn; scanf("%d %d %d", &n, &m, &qn); u.resize(n); s.resize(n, 1); p.resize(n); for (int i = 0; i < n; i++) { u[i] = i; } vector<pair<int, int>> e(m); for (int i = 0; i < m; i++) { int a, b; scanf("%d %d", &a, &b); a--;b--; e[i] = make_pair(a, b); //printf("%d %d %d\n", a, b, i); } int cycle = -1; for (int j = m-1; j >= 0; j--) { int a = e[j].first; int b = e[j].second; //printf("%d: (%d %d) (%d %d) (%d %d)\n", j, a, b, find(a), find(b), parity(a), parity(b)); if (find(a) == find(b)) { if (parity(a) == parity(b)) { cycle = j; break; } } else { unite(a, b); } } //printf("%d\n", cycle); for (int i = 0; i < qn; i++) { int l, r; scanf("%d %d", &l, &r); l--;r--; if (r <= cycle) { printf("YES\n"); } else { printf("NO\n"); } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 58 ms | 3644 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |