Submission #953484

#TimeUsernameProblemLanguageResultExecution timeMemory
953484Darren0724Port Facility (JOI17_port_facility)C++17
22 / 100
6070 ms40272 KiB
#include <bits/stdc++.h> using namespace std; #define LCBorz ios_base::sync_with_stdio(false); cin.tie(0); #define int long long #define all(x) x.begin(), x.end() #define endl '\n' const int N=200005; const int INF=1e18; const int mod=1e9+7; vector<int> adj[N],vis(N),dis(N); void dfs(int k,int pa){ vis[k]=1; for(int j:adj[k]){ if(j==pa)continue; if(!vis[j]){ dis[j]=dis[k]+1; dfs(j,k); } else if(dis[j]%2==dis[k]%2){ cout<<0<<endl; exit(0); } } } int32_t main() { LCBorz; int n;cin>>n; vector<int> a(n),b(n); for(int i=0;i<n;i++){ cin>>a[i]>>b[i]; } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i==j)continue; int cnt=(a[j]>=a[i]&&a[j]<=b[i])+(b[j]>=a[i]&&b[j]<=b[i]); if(cnt==1){ adj[i].push_back(j); } } } int ans=1; for(int i=0;i<n;i++){ if(!vis[i]){ ans=ans*2%mod; dfs(i,i); } } cout<<ans<<endl; 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...