# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79446 | Plurm | Port Facility (JOI17_port_facility) | C++11 | 888 ms | 1049600 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;
dfs(v,u,c);
}
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);
}
for(int i = 0; i < n; i++){
for(int j = i+1; j < n; j++){
if(pts[j].first < pts[i].first && pts[i].first < pts[j].second && pts[j].second < pts[i].second){
g[j].push_back(i);
g[i].push_back(j);
}else if(pts[i].first < pts[j].first && pts[j].first < pts[i].second && pts[i].second < pts[j].second){
g[j].push_back(i);
g[i].push_back(j);
}
}
}
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... |