# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
765215 | 2023-06-24T09:25:47 Z | oyber | Joker (BOI20_joker) | C++14 | 105 ms | 16568 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[ap] > s[bp]) { swap(a, b); swap(ap, bp); } u[bp] = ap; s[ap] += s[bp]; if (parity(a) == parity(b)) { p[b] = 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<vector<int>> e(n); for (int i = 0; i < m; i++) { int u, v; scanf("%d %d", &u, &v); u--;v--; e[u].push_back(v); e[v].push_back(u); } vector<pair<int, int>> q(qn); vector<int> q2(qn); for (int i = 0; i < qn; i++) { int l, r; scanf("%d %d", &l, &r); l--;r--; q.push_back(make_pair(r, i)); q2.push_back(r); } sort(q.begin(), q.end(), greater<pair<int, int>>()); int cycle = -1; for (int j = n-1; j >= 0; j--) { for (int k = 0; k < int(e[j].size()); k++) { if (e[j][k] > j) { int a = j; int b = e[j][k]; if (find(a) == find(b)) { if (parity(a) == parity(b)) { cycle = j; break; } } else { unite(a, b); } } } if (cycle != -1) break; } //printf("%d\n", cycle); for (int i = 0; i < qn; i++) { if (q2[i] <= 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 | 292 KB | Output is correct |
3 | Incorrect | 1 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 | 292 KB | Output is correct |
3 | Incorrect | 1 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 | 292 KB | Output is correct |
3 | Incorrect | 105 ms | 16568 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 | 292 KB | Output is correct |
3 | Incorrect | 1 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 | 292 KB | Output is correct |
3 | Incorrect | 1 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 | 292 KB | Output is correct |
3 | Incorrect | 1 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |