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;
#define int long long
const int mod = 1000000007;
int bm(int b, int pw) {
if (!pw) return 1;
int res = bm(b, pw / 2);
res = res * res % mod;
if (pw % 2 == 1) res = res * b % mod;
return res;
}
int p[1000001];
int find(int u) {
return p[u] == u ? u : p[u] = find(p[u]);
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, cnt = 0;
cin >> n;
vector<pair<int, int>> a(n);
vector<int> compo(n, 0);
for (int i = 0; i < n; i++) p[i] = i;
for (auto& [x, y] : a) cin >> x >> y;
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[j].first < a[i].second && a[i].second < a[j].second) {
if (find(i) != find(j)) p[find(j)] = find(i);
else return cout << "0\n", 0;
}
}
}
for (int i = 0; i < n; i++) compo[find(i)] = 1;
for (int i = 0; i < n; i++) cnt += compo[i];
cout << bm(2, cnt) << '\n';
}
# | 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... |