# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79453 | Plurm | Port Facility (JOI17_port_facility) | C++11 | 6093 ms | 38284 KiB |
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>
using namespace std;
vector<int> g[1000005];
int col[1000005];
bool dfs(int u,int p = -1,int c = 1){
col[u] = c;
c = c % 2 + 1;
for(int v : g[u]){
if(v == p) continue;
if(col[v] && col[v] != c) return false;
if(col[v]) continue;
if(!dfs(v,u,c)) return false;
}
return true;
}
int main(){
int n;
scanf("%d",&n);
vector<pair<int,int> > pts;
int a,b;
for(int i = 0; i < n; i++){
scanf("%d%d",&a,&b);
pts.emplace_back(a,b);
}
sort(pts.begin(),pts.end());
for(int i = 0; i < n; i++){
int bc = 0;
pair<int,int> x,y;
for(int j = i+1; j < n && pts[j].first < pts[i].second; j++){
if(pts[i].second < pts[j].second){
if(bc == 0) x = pts[j];
else y = pts[j];
g[j].push_back(i);
g[i].push_back(j);
bc++;
}
if(bc == 2 && x.first < y.first && y.first < x.second && x.second < y.second){
printf("0\n");
return 0;
}
}
}
int c = 0;
for(int i = 0; i < n; i++){
if(!col[i]){
if(dfs(i)) c++;
else{
printf("0\n");
return 0;
}
}
}
int ans = 1;
for(int i = 0; i < c; i++){
ans *= 2;
ans %= 1000000007;
}
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
# | 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... |