Submission #1037415

#TimeUsernameProblemLanguageResultExecution timeMemory
1037415woodJoker (BOI20_joker)C++17
14 / 100
2036 ms10832 KiB
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> p32;
typedef vector<p32> vp32;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second 

int main(){
	int n,m,q; cin>>n>>m>>q;
	vp32 adj[n];
	for(int i = 0; i<m; i++){
		int a,b; cin>>a>>b;
		a--; b--;
		adj[a].eb(b,i+1);
		adj[b].eb(a,i+1);
	}
	for(int j = 0; j<q; j++){
		int l,r; cin>>l>>r;
		int parent[n];
		int depth[n];
		memset(parent,0,sizeof parent);
		memset(depth,0,sizeof depth);
		stack<int> qu;
		for(int i = 0; i<n; i++){
			if(!parent[i]){
				parent[i] = i+1;
				qu.push(i);
				while(!qu.empty()){
					int x = qu.top();
					depth[x] = depth[parent[x]-1]+1;
					qu.pop();
					for(p32 tt : adj[x]){
						if(tt.se<l||tt.se>r){
							if(depth[tt.fi]&&parent[x]-1!=tt.fi&&((depth[x]-depth[tt.fi]+1)&1)) goto found;
							if(parent[tt.fi]==0){
								parent[tt.fi] = x+1;
								qu.push(tt.fi);
							}
						}
					}
				}
			}
		}
		cout<<"NO\n";
		continue;
found:
		cout<<"YES\n";
	}
	return 0;
}
#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...