제출 #1166183

#제출 시각아이디문제언어결과실행 시간메모리
1166183mannshah1211Port Facility (JOI17_port_facility)C++20
22 / 100
6094 ms16968 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "deb.h" #else #define debug(...) #endif const int M = 1e9 + 7; void solve() { int n; cin >> n; vector<int> a(n), b(n), d(2 * n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; --a[i]; --b[i]; d[a[i]] = i + 1; d[b[i]] = -i - 1; } vector<vector<int>> g(n); auto Add = [&](int u, int v) -> void { --u; --v; g[u].push_back(v); g[v].push_back(u); }; set<int> active; for (int i = 0; i < 2 * n; i++) { if (d[i] > 0) { active.insert(d[i]); } else { active.erase(-d[i]); for (int obstacle : active) { if (a[obstacle - 1] > a[-d[i] - 1]) { Add(obstacle, -d[i]); } } } } vector<int> c(n, -1); bool bipartite = true; int comps = 0; auto Dfs = [&](auto&& self, int v) -> void { for (int u : g[v]) { if (c[u] == c[v]) { bipartite = false; return; } else { if (c[u] == -1) { c[u] = c[v] ^ 1; self(self, u); } } } }; for (int i = 0; i < n; i++) { if (c[i] == -1) { comps += 1; c[i] = 0; Dfs(Dfs, i); } } if (!bipartite) { cout << 0 << '\n'; return; } int ans = 1; for (int i = 0; i < comps; i++) { ans *= 2; ans %= M; } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } 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...