Submission #289906

#TimeUsernameProblemLanguageResultExecution timeMemory
289906someone_aaJoker (BOI20_joker)C++17
25 / 100
1503 ms17912 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define pii pair<int,int> using namespace std; const int maxn = 200100; ll n, m, q; vector<pii>g[maxn]; bool visited[maxn]; int color[maxn]; bool check(int l, int r) { memset(visited, false,sizeof(visited)); memset(color, 0, sizeof(color)); bool cycle = false; for(int i=1;i<=n;i++) { if(!visited[i]) { visited[i] = true; color[i] = 1; queue<int>q; q.push(i); while(!q.empty()) { int curr = q.front(); q.pop(); for(auto i:g[curr]) { if(l <= i.second && i.second <= r) continue; if(!visited[i.first]) { visited[i.first] = true; color[i.first] = 3 - color[curr]; q.push(i.first); } else { if(color[i.first] == color[curr]) cycle = true; } } } } } return cycle; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>m>>q; int u, v; for(int i=1;i<=m;i++) { cin>>u>>v; g[u].pb(mp(v, i)); g[v].pb(mp(u, i)); } if(!check(1, 1)) { for(int i=0;i<q;i++) { cout<<"NO\n"; } return 0; } int rmost = 1; for(ll cekor=m/2;cekor>0;cekor/=2) { while(rmost + cekor <= m && check(1, rmost+cekor)) rmost += cekor; } int l, r; while(q--) { cin>>l>>r; if(r <= rmost) cout<<"YES\n"; else cout<<"NO\n"; } }
#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...