# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1033874 | 2024-07-25T07:20:37 Z | goodspeed0208 | Joker (BOI20_joker) | C++14 | 2000 ms | 6100 KB |
#include<bits/stdc++.h> #define pii pair<int, int> using namespace std; int n, m, q; vector<int>f, sz, same, dif; void init() { for (int i = 0 ; i < n ; i++) { f[i] = i; same[i] = i; dif[i] = -1; sz[i] = 1; } } int find(int x) { //if (f[x][j] == -1) return -1; if (x == f[x]) return x; else return f[x] = find(f[x]); } int finds(int x) { if (x == same[x]) return x; else return same[x] = find(same[x]); } bool add(int a, int b) { int fa = find(a), fb = find(b); int sa = finds(a), sb = finds(b); //cout << fa << " " << sa << " " << fb << " " << sb << "\n"; if (fa == fb) { if (sa == sb) return true; } if (sz[fa] > sz[fb]) swap(fa, fb); swap(sa, sb); f[fa] = fb; sz[fb] += sz[fa]; if ((fa == sa && fb == sb) || (fa != sa && fb != sb)) { if (dif[fa] != -1) same[dif[fa]] = same[fb]; if (dif[fb] != -1) same[fa] = same[dif[fb]]; else dif[fb] = fa; } else { same[fa] = same[fb]; if (dif[fa] != -1 && dif[fb] != -1) same[dif[fa]] = same[dif[fb]]; else if (dif[fa] != -1) dif[fb] = fa; } return false; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> q; f.resize(n); sz.resize(n, 1); same.resize(n); dif.resize(n); vector<pii>e; int a, b; for (int i = 0 ; i < m ; i++) { cin >> a >> b; a--, b--; e.push_back({a, b}); } int l, r; for (int i = 0 ; i < q ; i++) { init(); bool can = 0; cin >> l>> r; l--, r--; for (int j = 0 ; j < l && !can ; j++) { //cout << e[j].first << " " << e[j].second << "\n"; can = add(e[j].first, e[j].second); //cout << j << " "; } for (int j = r+1 ; j < m && !can ; j++) { can = add(e[j].first, e[j].second); //cout << j << " "; } if (can) cout <<"YES\n"; else cout << "NO\n"; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Incorrect | 0 ms | 348 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Incorrect | 0 ms | 348 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Execution timed out | 2066 ms | 6100 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Incorrect | 0 ms | 348 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Incorrect | 0 ms | 348 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Incorrect | 0 ms | 348 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |