Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo314 committed May 5, 2024
1 parent 24678dc commit b85f1ac
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/aoj-jag-summer-2971.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/challenges/sources/JAG/Summer/2971"

#include <array>
#include <iostream>

#include "../cpp/modint.hpp"
#include "../cpp/potentialized-unionfind.hpp"

template <typename mint>
bool solve(int n, const std::vector<std::array<int, 3>>& abx) {
UnionFindMul<mint> uf(n);
for (auto [a, b, x] : abx) {
mint mx = x;
if (mx != 0) {
if (uf.same(a, b)) {
if (uf.diff(a, b) != mx) {
return false;
}
} else {
uf.merge(a, b, mx);
}
}
}
return true;
}

int main() {
using mint3 = modint998244353;
using mint7 = modint1000000007;
using mint9 = static_modint<1000000009U>;
int n, m;
std::cin >> n >> m;
std::vector<std::array<int, 3>> abx(m);
for (auto& [a, b, x] : abx) {
std::cin >> a >> b >> x;
a--;
b--;
}
if (solve<mint3>(n, abx) && solve<mint7>(n, abx) && solve<mint9>(n, abx)) {
std::cout << "Yes" << std::endl;
} else {
std::cout << "No" << std::endl;
}
}

0 comments on commit b85f1ac

Please sign in to comment.