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>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int mod=1e9+7;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);
int n;
cin>>n;
vector <int> l(n),r(n);
for(int i=0;i<n;i++){
cin>>l[i]>>r[i];
}
vector <int> g[n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(l[i]<l[j] && r[j]>r[i] && l[j]<r[i]){
g[i].pb(j);
g[j].pb(i);
}
}
}
queue <int> q;
vector <int> vis(n);
int cnt=0;
for(int i=0;i<n;i++){
if(!vis[i]){
cnt++;
q.push(i);
vis[i]=1;
while(!q.empty()){
int v=q.front();
q.pop();
for(auto to : g[v]){
if(!vis[to]){
vis[to]=1;
q.push(to);
}
}
}
}
}
for(int i=0;i<n;i++)vis[i]=0;
bool flag=true;
for(int i=0;i<n;i++){
if(!vis[i]){
q.push(i);
vis[i]=1;
while(!q.empty()){
int v=q.front();
q.pop();
for(auto to : g[v]){
if(!vis[to]){
if(vis[v]==1)vis[to]=2;
if(vis[v]==2)vis[to]=1;
q.push(to);
}
else if(vis[to]==vis[v]){
flag=false;break;
}
}
}
}
}
if(flag){
int x=1;
for(int i=0;i<cnt;i++){
x*=2;
x%=mod;
}
cout<<x<<"\n";
}
else cout<<0<<"\n";
}
# | 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... |