# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
416990 | aryan12 | Joker (BOI20_joker) | C++17 | 2074 ms | 20348 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;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int N = 200005;
vector<int> g[N];
int color[N];
bool dfs(int node, int col) {
color[node] = col;
for(int i = 0; i < g[node].size(); i++) {
if(color[g[node][i]] == -1) {
if(dfs(g[node][i], 1 - col))
return true;
}
else if(color[g[node][i]] == color[node])
return true;
}
return false;
}
bool isBipartite(int n) {
for(int i = 1; i <= n; i++) {
if(color[i] == -1) {
if(dfs(i, 0))
return true;
}
}
return false;
}
void Solve() {
int n, m, q;
cin >> n >> m >> q;
vector<pair<int, int> > edges;
for(int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
edges.push_back(make_pair(u, v));
}
for(int i = 1; i <= q; i++) {
for(int i = 0; i <= n; i++) {
color[i] = -1;
g[i].clear();
}
int left, right;
cin >> left >> right;
left--, right--;
for(int i = 0; i < left; i++) {
g[edges[i].first].push_back(edges[i].second);
g[edges[i].second].push_back(edges[i].first);
}
for(int i = right + 1; i < m; i++) {
g[edges[i].first].push_back(edges[i].second);
g[edges[i].second].push_back(edges[i].first);
}
if(isBipartite(n)) {
cout << "YES\n";
}
else {
cout << "NO\n";
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--) {
Solve();
}
return 0;
}
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... |