This documentation is automatically generated by competitive-verifier/competitive-verifier
// competitive-verifier: PROBLEM https://yukicoder.me/problems/no/274
// competitive-verifier: TLE 0.5
// competitive-verifier: MLE 64
// ポテンシャルUF(無向2SAT)
#include <iostream>
#include "src/DataStructure/UnionFind_Potentialized.hpp"
using namespace std;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int N, M;
cin >> N >> M;
int L[N], R[N];
for (int i= 0; i < N; ++i) cin >> L[i] >> R[i];
UnionFind_Potentialized<bool> uf(N);
for (int i= N; i--;)
for (int j= i; j--;) {
if (!(R[i] < L[j] || R[j] < L[i]))
if (!uf.unite(i, j, 1)) return cout << "NO" << '\n', 0;
if (!(R[i] < M - 1 - R[j] || M - 1 - L[j] < L[i]))
if (!uf.unite(i, j, 0)) return cout << "NO" << '\n', 0;
}
cout << "YES" << '\n';
return 0;
}
#line 1 "test/yukicoder/274.UFP.test.cpp"
// competitive-verifier: PROBLEM https://yukicoder.me/problems/no/274
// competitive-verifier: TLE 0.5
// competitive-verifier: MLE 64
// ポテンシャルUF(無向2SAT)
#include <iostream>
#line 2 "src/DataStructure/UnionFind_Potentialized.hpp"
#include <vector>
#include <algorithm>
#include <cassert>
template <class weight_t> class UnionFind_Potentialized {
std::vector<int> par;
std::vector<weight_t> val;
public:
UnionFind_Potentialized(int n): par(n, -1), val(n) {}
int leader(int u) {
if (par[u] < 0) return u;
int r= leader(par[u]);
if constexpr (std::is_same_v<weight_t, bool>) val[u]= val[u] ^ val[par[u]];
else val[u]= val[par[u]] + val[u];
return par[u]= r;
}
// -p(v) + p(u) = w
bool unite(int u, int v, weight_t w) {
int a= leader(u), b= leader(v);
if constexpr (std::is_same_v<weight_t, bool>) w^= val[u] ^ val[v];
else w= val[v] + w - val[u];
if (a == b) return w == weight_t();
if (par[b] > par[a]) std::swap(a, b), w= -w;
return par[b]+= par[a], par[a]= b, val[a]= w, true;
}
bool connected(int u, int v) { return leader(u) == leader(v); }
int size(int u) { return -par[leader(u)]; }
weight_t potential(int u) { return leader(u), val[u]; }
// -p(v) + p(u)
weight_t diff(int u, int v) {
if constexpr (std::is_same_v<weight_t, bool>) return potential(u) ^ potential(v);
else return -potential(v) + potential(u);
}
};
#line 7 "test/yukicoder/274.UFP.test.cpp"
using namespace std;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int N, M;
cin >> N >> M;
int L[N], R[N];
for (int i= 0; i < N; ++i) cin >> L[i] >> R[i];
UnionFind_Potentialized<bool> uf(N);
for (int i= N; i--;)
for (int j= i; j--;) {
if (!(R[i] < L[j] || R[j] < L[i]))
if (!uf.unite(i, j, 1)) return cout << "NO" << '\n', 0;
if (!(R[i] < M - 1 - R[j] || M - 1 - L[j] < L[i]))
if (!uf.unite(i, j, 0)) return cout << "NO" << '\n', 0;
}
cout << "YES" << '\n';
return 0;
}
Env | Name | Status | Elapsed | Memory |
---|---|---|---|---|
g++-13 | 98_challenge01.txt |
![]() |
5 ms | 4 MB |
g++-13 | 99_system_test1.txt |
![]() |
5 ms | 4 MB |
g++-13 | 99_system_test2.txt |
![]() |
5 ms | 4 MB |
g++-13 | 99_system_test3.txt |
![]() |
5 ms | 4 MB |
g++-13 | 99_system_test4.txt |
![]() |
5 ms | 4 MB |
g++-13 | challenge01.txt |
![]() |
5 ms | 4 MB |
g++-13 | sample1.txt |
![]() |
5 ms | 4 MB |
g++-13 | sample2.txt |
![]() |
5 ms | 4 MB |
g++-13 | sample3.txt |
![]() |
5 ms | 4 MB |
g++-13 | sample4.txt |
![]() |
5 ms | 4 MB |
g++-13 | system_test1.txt |
![]() |
5 ms | 4 MB |
g++-13 | test1.txt |
![]() |
5 ms | 4 MB |
g++-13 | test10.txt |
![]() |
9 ms | 4 MB |
g++-13 | test11.txt |
![]() |
9 ms | 4 MB |
g++-13 | test12.txt |
![]() |
9 ms | 4 MB |
g++-13 | test13.txt |
![]() |
10 ms | 4 MB |
g++-13 | test14.txt |
![]() |
10 ms | 4 MB |
g++-13 | test15.txt |
![]() |
10 ms | 4 MB |
g++-13 | test16.txt |
![]() |
10 ms | 4 MB |
g++-13 | test2.txt |
![]() |
5 ms | 4 MB |
g++-13 | test3.txt |
![]() |
7 ms | 4 MB |
g++-13 | test4.txt |
![]() |
5 ms | 4 MB |
g++-13 | test5.txt |
![]() |
5 ms | 4 MB |
g++-13 | test6.txt |
![]() |
7 ms | 4 MB |
g++-13 | test7.txt |
![]() |
5 ms | 4 MB |
g++-13 | test8.txt |
![]() |
5 ms | 4 MB |
g++-13 | test9.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 98_challenge01.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 99_system_test1.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 99_system_test2.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 99_system_test3.txt |
![]() |
5 ms | 4 MB |
clang++-18 | 99_system_test4.txt |
![]() |
5 ms | 4 MB |
clang++-18 | challenge01.txt |
![]() |
5 ms | 4 MB |
clang++-18 | sample1.txt |
![]() |
5 ms | 4 MB |
clang++-18 | sample2.txt |
![]() |
5 ms | 4 MB |
clang++-18 | sample3.txt |
![]() |
5 ms | 4 MB |
clang++-18 | sample4.txt |
![]() |
5 ms | 4 MB |
clang++-18 | system_test1.txt |
![]() |
5 ms | 4 MB |
clang++-18 | test1.txt |
![]() |
5 ms | 4 MB |
clang++-18 | test10.txt |
![]() |
9 ms | 4 MB |
clang++-18 | test11.txt |
![]() |
10 ms | 4 MB |
clang++-18 | test12.txt |
![]() |
10 ms | 4 MB |
clang++-18 | test13.txt |
![]() |
11 ms | 4 MB |
clang++-18 | test14.txt |
![]() |
11 ms | 4 MB |
clang++-18 | test15.txt |
![]() |
11 ms | 4 MB |
clang++-18 | test16.txt |
![]() |
11 ms | 4 MB |
clang++-18 | test2.txt |
![]() |
5 ms | 4 MB |
clang++-18 | test3.txt |
![]() |
7 ms | 4 MB |
clang++-18 | test4.txt |
![]() |
5 ms | 4 MB |
clang++-18 | test5.txt |
![]() |
6 ms | 4 MB |
clang++-18 | test6.txt |
![]() |
7 ms | 4 MB |
clang++-18 | test7.txt |
![]() |
5 ms | 4 MB |
clang++-18 | test8.txt |
![]() |
5 ms | 4 MB |
clang++-18 | test9.txt |
![]() |
5 ms | 4 MB |