Submission #948459

#TimeUsernameProblemLanguageResultExecution timeMemory
948459dimashhhJoker (BOI20_joker)C++17
0 / 100
207 ms262144 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 5, MOD = 998244353; int p[N],sz[N],n,m,q,d[N]; void reset(){ for(int i = 1;i <= n;i++){ sz[i] = 1; p[i] = i; d[i] = 0; } } pair<int, int> get(int v) { if(p[v] == v){ return {v,0}; } pair<int,int> x = get(p[v]); return {p[v],d[v]+x.second}; } bool merge(int a,int b){ pair<int,int> x = get(a),y = get(b); if(sz[x.first] < sz[y.first]){ swap(x,y); } a = x.first; b = y.first; if(a == b){ if(x.second % 2 == y.second % 2){ return false; } return true; } p[b] = a; sz[a] += sz[b]; d[b] = (x.second % 2 == y.second % 2); return true; } int x[N],y[N]; vector<pair<int,int>> qr[N]; vector<int> ids[N]; bool ans[N]; void test(){ cin >> n >> m >> q; for(int i = 1;i <= m;i++){ cin >> x[i] >> y[i]; } for(int i = 1;i <= q;i++){ int l,r; cin >> l >> r; qr[l].push_back({i,r}); } for(int i = 1;i <= m;i++){ if(qr[i].size()){ reset(); }else continue; for(int j = i;j <= m;j++){ ids[j].clear(); } for(auto [id,j]:qr[i]){ ids[j].push_back(id); } bool is = true; for(int j = 1;j < i;j++) { is &= merge(x[j],y[j]); } for(int j = m;j >= i;j--){ for(int k:ids[j]){ ans[k] = (!is); } is &= merge(x[j],y[j]); } } for(int i = 1;i <= q;i++){ cout << (ans[i] ? "YES\n":"NO\n"); } } int main(){ ios_base::sync_with_stdio(false);cin.tie(0); int T = 1; // cin >> T; while(T--){ test(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...