Submission #244361

#TimeUsernameProblemLanguageResultExecution timeMemory
244361Osama_AlkhodairyPort Facility (JOI17_port_facility)C++17
22 / 100
6129 ms833588 KiB
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long const int N = 1000001; int n, vis[N], p[N], mod = 1e9 + 7; vector <pair <int, int> > a; vector <int> f, v[N]; void dfs(int node){ for(auto &i : v[node]){ if(vis[i] != -1 && vis[i] != (vis[node] ^ 1)){ cout << 0 << endl; exit(0); } if(vis[i] != -1) continue; vis[i] = vis[node] ^ 1; dfs(i); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); memset(vis, -1, sizeof vis); cin >> n; a.resize(n); f.resize(2 * n); for(int i = 0 ; i < n ; i++){ cin >> a[i].first >> a[i].second; a[i].first--; a[i].second--; f[a[i].first] = f[a[i].second] = i; p[i] = i; } vector <int> o, del(n); for(int i = 0 ; i < 2 * n ; i++){ while(o.size() && del[o.back()]){ o.pop_back(); } if(a[f[i]].first == i){ o.push_back(f[i]); } else{ del[f[i]] = 1; int j = (int)o.size() - 1; while(o[j] != f[i]){ if(del[o[j]] == 0){ v[f[i]].push_back(o[j]); v[o[j]].push_back(f[i]); } j--; } } } int ans = 1; for(int i = 0 ; i < n ; i++){ if(vis[i] != -1) continue; ans *= 2; if(ans >= mod) ans -= mod; vis[i] = 0; dfs(i); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...