# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1123684 | KhanhDang | Joker (BOI20_joker) | C++20 | 369 ms | 66112 KiB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define Unique(v) sort(all(v)); (v).erase(unique(all(v)), (v).end());
const ll N = 1e6+5;
ll n, m, q;
ll x[N], y[N];
ll dd[N], ans[N];
vector<ll> adj[N];
vector<pll> qu[N];
bool dfs(ll u, ll p) {
for (auto v : adj[u]) {
if (v == p) continue;
if (dd[v]) {
if (dd[v] % 2 == dd[u] % 2)
return true;
} else {
dd[v] = dd[u] + 1;
if (dfs(v, u)) return true;
}
}
return false;
}
bool check(ll mid, ll id) {
for (int i = 1; i < id; i++) {
adj[x[i]].push_back(y[i]);
adj[y[i]].push_back(x[i]);
}
for (int i = mid+1; i <= m; i++) {
adj[x[i]].push_back(y[i]);
adj[y[i]].push_back(x[i]);
}
fill(dd+1, dd+n+1, 0);
bool ok = false;
for (int i = 1; i <= n; i++) {
if (dd[i]) continue;
dd[i] = 1;
ok = dfs(i, i);
if (ok) break;
}
for (int i = 1; i <= n; i++)
adj[i].clear();
return ok;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "NOHOME"
if (fopen(task".INP", "r")) {
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
if (fopen("task.INP", "r")) {
freopen("task.INP", "r", stdin);
freopen("task.OUT", "w", stdout);
}
cin>>n>>m>>q;
for (int i = 1; i <= m; i++)
cin>>x[i]>>y[i];
for (int i = 1; i <= q; i++) {
ll l, r; cin>>l>>r;
qu[l].push_back({r, i});
}
for (int i = 1; i <= n; i++) {
if (qu[i].empty()) continue;
ll l = i, r = m, res = 0;
while (l <= r) {
ll mid = (l+r)>>1;
if (check(mid, i)) {
res = mid;
l = mid + 1;
}
else r = mid - 1;
}
for (auto v : qu[i]) ans[v.se] = (v.fi <= res) ;
}
for (int i = 1; i <= q; i++)
cout<<(ans[i] ? "YES\n" : "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... |