Submission #953546

#TimeUsernameProblemLanguageResultExecution timeMemory
953546Darren0724Port Facility (JOI17_port_facility)C++17
0 / 100
9 ms16476 KiB
#include <bits/stdc++.h> #include <bits/extc++.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; struct DSU{ vector<int> pa,sz; DSU(int n){ pa.resize(n<<1); sz.resize(n<<1); } int Find(int k){ return pa[k]=Find(pa[k])?k:pa[k]=Find(pa[k]); } void unite(int a,int b){ a=Find(a),b=Find(b); if(a==b)return; if(sz[a]>sz[b])swap(a,b); pa[a]=b; sz[b]+=sz[a]; } int onion(int a,int b){ unite(a,b+N); unite(a+N,b); return Find(a)==Find(a+N); } }; 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]; } int cnt1=0; 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){ cnt1++; adj[i].push_back(j); } } } assert(cnt1<=5*n); 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...