# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
930540 | Ghulam_Junaid | Joker (BOI20_joker) | C++17 | 2094 ms | 211884 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int n, m, q, vis_nq[N], par[N], col[N];
vector<pair<int, int>> g[N], atl[N];
pair<int, int> edge[N];
vector<int> S[N];
bool ans[N];
int root(int v){
return (par[v] == -1 ? v : root(par[v]));
}
inline bool merge(int u, int v){
int r1 = root(u);
int r2 = root(v);
if (r1 == r2)
return (col[u] != col[v]);
if (S[r2].size() > S[r1].size())
swap(r1, r2);
par[r2] = r1;
int take = 0;
if (col[u] == col[v])
take = 3;
for (int x : S[r2]){
col[x] ^= take;
S[r1].push_back(x);
}
S[r2].clear();
return 1;
}
int main(){
scanf("%d%d%d", &n, &m, &q);
for (int i = 1; i <= m; i ++){
int u, v;
scanf("%d%d", &u, &v);
g[u].push_back({i, v});
g[v].push_back({i, u});
edge[i] = {u, v};
}
int mx = 0;
for (int i = 0; i < q; i ++){
int l, r;
scanf("%d%d", &l, &r);
mx = max(mx, l);
atl[l].push_back({r, i});
}
for (int i = 1; i <= m; i ++){
sort(atl[i].begin(), atl[i].end());
reverse(atl[i].begin(), atl[i].end());
}
for (int i = 1; i <= mx; i ++){
if (atl[i].size() == 0) continue;
for (int j = 1; j <= n; j ++){
S[j] = {j};
par[j] = -1;
col[j] = 1;
}
bool even = 1;
for (int j = 1; j < i; j ++)
even &= merge(edge[j].first, edge[j].second);
int x = m;
for (auto [r, id] : atl[i]){
for (int j = r + 1; j <= x; j ++)
even &= merge(edge[j].first, edge[j].second);
x = r;
if (even)
ans[id] = 0;
else
ans[id] = 1;
}
}
for (int i = 0; i < q; i ++){
if (ans[i])
printf("YES\n");
else
printf("NO\n");
}
}
Compilation message (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... |