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 jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
vector<int> G[1000005];
pii seg[1000005];
int color[1000005];
bool dfs(int u,int c)
{
color[u]=c;
for(int i:G[u])
if(!~color[i]&&!dfs(i,c^1))
return 0;
else if(color[i]==color[u])
return 0;
return 1;
}
int main()
{jizz
int n,cnt=0,flag=1,ans=1;
cin >> n;
for(int i=0;i<n;++i)
cin >> seg[i].F >> seg[i].S;
sort(seg,seg+n);
for(int i=0;i<n;++i)
for(int j=i+1;j<n;++j)
if(seg[i].S>seg[j].F&&seg[j].S>seg[i].S)
G[i].pb(j),G[j].pb(i);
MEM(color,-1);
for(int i=0;i<n&&flag;++i)
if(!~color[i])
flag&=dfs(i,0),++cnt;
if(flag)
while(cnt--)
ans=ans*2%MOD;
if(flag) cout << ans << "\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... |