From dc46462a627710532ec16d2775b41c2a51644956 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Fri, 7 Feb 2025 10:44:44 -0500 Subject: [PATCH] feat(codeforces): 998 --- codeforces/998/.clang-format | 9 + codeforces/998/.clangd | 8 + codeforces/998/a.cc | 99 +++++++++ codeforces/998/a.in | 7 + codeforces/998/a.out | 9 + codeforces/998/b.cc | 118 +++++++++++ codeforces/998/b.in | 14 ++ codeforces/998/b.out | 7 + codeforces/998/c.cc | 108 ++++++++++ codeforces/998/c.in | 9 + codeforces/998/c.out | 8 + codeforces/998/compile_flags.txt | 5 + codeforces/998/d.cc | 120 +++++++++++ codeforces/998/d.in | 11 + codeforces/998/d.out | 8 + codeforces/998/e.cc | 185 +++++++++++++++++ codeforces/998/e.in | 17 ++ codeforces/998/e.out | 8 + codeforces/998/f.cc | 109 ++++++++++ codeforces/998/f.in | 4 + codeforces/998/f.out | 6 + codeforces/998/file.cc | 283 ++++++++++++++++++++++++++ codeforces/998/temp/.clang-format | 9 + codeforces/998/temp/.clangd | 8 + codeforces/998/temp/a.cc | 88 ++++++++ codeforces/998/temp/a.in | 1 + codeforces/998/temp/a.out | 9 + codeforces/998/temp/b.cc | 74 +++++++ codeforces/998/temp/b.in | 0 codeforces/998/temp/b.out | 0 codeforces/998/temp/compile_flags.txt | 5 + 31 files changed, 1346 insertions(+) create mode 100644 codeforces/998/.clang-format create mode 100644 codeforces/998/.clangd create mode 100644 codeforces/998/a.cc create mode 100644 codeforces/998/a.in create mode 100644 codeforces/998/a.out create mode 100644 codeforces/998/b.cc create mode 100644 codeforces/998/b.in create mode 100644 codeforces/998/b.out create mode 100644 codeforces/998/c.cc create mode 100644 codeforces/998/c.in create mode 100644 codeforces/998/c.out create mode 100644 codeforces/998/compile_flags.txt create mode 100644 codeforces/998/d.cc create mode 100644 codeforces/998/d.in create mode 100644 codeforces/998/d.out create mode 100644 codeforces/998/e.cc create mode 100644 codeforces/998/e.in create mode 100644 codeforces/998/e.out create mode 100644 codeforces/998/f.cc create mode 100644 codeforces/998/f.in create mode 100644 codeforces/998/f.out create mode 100644 codeforces/998/file.cc create mode 100644 codeforces/998/temp/.clang-format create mode 100644 codeforces/998/temp/.clangd create mode 100644 codeforces/998/temp/a.cc create mode 100644 codeforces/998/temp/a.in create mode 100644 codeforces/998/temp/a.out create mode 100644 codeforces/998/temp/b.cc create mode 100644 codeforces/998/temp/b.in create mode 100644 codeforces/998/temp/b.out create mode 100644 codeforces/998/temp/compile_flags.txt diff --git a/codeforces/998/.clang-format b/codeforces/998/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/998/.clang-format @@ -0,0 +1,9 @@ +BasedOnStyle: Google +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: false +AllowShortLoopsOnASingleLine: false diff --git a/codeforces/998/.clangd b/codeforces/998/.clangd new file mode 100644 index 0000000..61f8494 --- /dev/null +++ b/codeforces/998/.clangd @@ -0,0 +1,8 @@ +CompileFlags: + Add: + - -std=c++20 + - -Wall + - -Wextra + - -Wpedantic + - -Wshadow + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/codeforces/998/a.cc b/codeforces/998/a.cc new file mode 100644 index 0000000..90bc76d --- /dev/null +++ b/codeforces/998/a.cc @@ -0,0 +1,99 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +void solve() { + int a1, a2, a3, a4; + cin >> a1 >> a2 >> a3 >> a4; + + auto fibness = [](int a, int b, int c, int d, int e) { + return int(a + b == c) + int(b + c == d) + int(c + d == e); + }; + + int ans = MIN; + for (auto guess : {a3 - a2, a2 - a3, a1 + a2, a4 - a3}) + ans = max(ans, fibness(a1, a2, guess, a3, a4)); + + cout << ans << endl; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/998/a.in b/codeforces/998/a.in new file mode 100644 index 0000000..6627b4a --- /dev/null +++ b/codeforces/998/a.in @@ -0,0 +1,7 @@ +6 +1 1 3 5 +1 3 2 1 +8 10 28 100 +100 1 100 1 +1 100 1 100 +100 100 100 100 diff --git a/codeforces/998/a.out b/codeforces/998/a.out new file mode 100644 index 0000000..8f2c2db --- /dev/null +++ b/codeforces/998/a.out @@ -0,0 +1,9 @@ +3 +2 +2 +1 +1 +2 + +[code]: 0 +[time]: 11.7078 ms \ No newline at end of file diff --git a/codeforces/998/b.cc b/codeforces/998/b.cc new file mode 100644 index 0000000..ebc76f7 --- /dev/null +++ b/codeforces/998/b.cc @@ -0,0 +1,118 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +void solve() { + int n, m; + + cin >> n >> m; + + vec> cards(n, vec(m + 1)); + + FOR(i, 0, n) { + FOR(j, 0, m) { + cin >> cards[i][j]; + } + cards[i][m] = m * n; + sort(all(cards[i])); + cards[i][m] = i; + } + + sort(all(cards)); + + int last = -1; + FOR(j, 0, m) { + FOR(i, 0, n) { + if (cards[i][j] <= last) { + dbgln(-1); + return; + } + last = cards[i][j]; + } + } + + FOR(i, 0, n) { + cout << cards[i][m] + 1 << " \n"[i == n - 1]; + } +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/998/b.in b/codeforces/998/b.in new file mode 100644 index 0000000..471f391 --- /dev/null +++ b/codeforces/998/b.in @@ -0,0 +1,14 @@ +4 +2 3 +0 4 2 +1 5 3 +1 1 +0 +2 2 +1 2 +0 3 +4 1 +1 +2 +0 +3 diff --git a/codeforces/998/b.out b/codeforces/998/b.out new file mode 100644 index 0000000..81f66bd --- /dev/null +++ b/codeforces/998/b.out @@ -0,0 +1,7 @@ +1 2 +1 +-1 +3 1 2 4 + +[code]: 0 +[time]: 12.5709 ms \ No newline at end of file diff --git a/codeforces/998/c.cc b/codeforces/998/c.cc new file mode 100644 index 0000000..9f342c2 --- /dev/null +++ b/codeforces/998/c.cc @@ -0,0 +1,108 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +vec a; + +void solve() { + int n, k; + cin >> n >> k; + a.resize(n); + for (auto &e : a) + cin >> e; + sort(all(a)); + int ans = 0; + int l = 0, r = sz(a) - 1; + while (l < r) { + if (a[l] + a[r] == k) { + ++l; + --r; + ++ans; + } else if (a[l] + a[r] < k) + ++l; + else + --r; + } + dbgln(ans); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/998/c.in b/codeforces/998/c.in new file mode 100644 index 0000000..f0c579c --- /dev/null +++ b/codeforces/998/c.in @@ -0,0 +1,9 @@ +4 +4 4 +1 2 3 2 +8 15 +1 2 3 4 5 6 7 8 +6 1 +1 1 1 1 1 1 +16 9 +3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 diff --git a/codeforces/998/c.out b/codeforces/998/c.out new file mode 100644 index 0000000..768b15c --- /dev/null +++ b/codeforces/998/c.out @@ -0,0 +1,8 @@ +2 +1 +0 +4 + 0 +[code]: 0 +[time]: 7.88546 ms +[time]: 2.94971 ms \ No newline at end of file diff --git a/codeforces/998/compile_flags.txt b/codeforces/998/compile_flags.txt new file mode 100644 index 0000000..b5d4b68 --- /dev/null +++ b/codeforces/998/compile_flags.txt @@ -0,0 +1,5 @@ +-std=c++20 +-Wall +-Wextra +-Wpedantic +-Wshadow diff --git a/codeforces/998/d.cc b/codeforces/998/d.cc new file mode 100644 index 0000000..0dddd2d --- /dev/null +++ b/codeforces/998/d.cc @@ -0,0 +1,120 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +static void YES() { + std::cout << "YES\n"; +} + +static void NO() { + std::cout << "NO\n"; +} + +vec a; + +void solve() { + int n; + cin >> n; + a.resize(n); + for (auto &e : a) + cin >> e; + + if (a[0] > a[1]) { + NO(); + return; + } + + a[1] -= a[0]; + + FOR(i, 2, n) { + auto x = min(a[i], a[i - 1]); + a[i - 1] -= x; + a[i] -= x; + if (a[i - 1] > a[i]) { + NO(); + return; + } + } + YES(); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/998/d.in b/codeforces/998/d.in new file mode 100644 index 0000000..d6a6398 --- /dev/null +++ b/codeforces/998/d.in @@ -0,0 +1,11 @@ +5 +5 +1 2 3 4 5 +4 +4 3 2 1 +4 +4 5 2 3 +8 +4 5 4 5 4 5 4 5 +9 +9 9 8 2 4 4 3 5 3 diff --git a/codeforces/998/d.out b/codeforces/998/d.out new file mode 100644 index 0000000..14d8793 --- /dev/null +++ b/codeforces/998/d.out @@ -0,0 +1,8 @@ +YES +NO +YES +YES +NO + +[code]: 0 +[time]: 11.3099 ms \ No newline at end of file diff --git a/codeforces/998/e.cc b/codeforces/998/e.cc new file mode 100644 index 0000000..74c9e29 --- /dev/null +++ b/codeforces/998/e.cc @@ -0,0 +1,185 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int a = (b); (a) > (c); --(a)) + +struct union_find { + public: + union_find(size_t n = 0) : par(n + 1), rank(n + 1, 0) { + for (size_t u = 0; u < n + 1; ++u) + par[u] = u; + }; + + void join(int u, int v) { + u = find(u), v = find(v); + + if (u == v) + return; + + if (rank[u] < rank[v]) + std::swap(u, v); + + if (rank[u] == rank[v]) + ++rank[u]; + + par[v] = u; + } + + int find(int u) { + if (u != par[u]) + par[u] = find(par[u]); + return par[u]; + } + + void reset(size_t capacity) { + par.resize(capacity); + std::iota(par.begin(), par.end(), 0); + rank.resize(capacity); + } + + std::vector par; + std::vector rank; +}; + +vec> F, G; +union_find Fuf, Guf; +unordered_set to_erase; + +void solve() { + int n, m1, m2; + cin >> n >> m1 >> m2; + + F.clear(); + F.resize(n + 1); + G.clear(); + G.resize(n + 1); + + Fuf.reset(n + 1); + Guf.reset(n + 1); + + FOR(i, 0, m1) { + int u, v; + cin >> u >> v; + F[u].insert(v); + F[v].insert(u); + } + + FOR(i, 0, m2) { + int u, v; + cin >> u >> v; + G[u].insert(v); + G[v].insert(u); + Guf.join(u, v); + } + + int ans = 0; + + FOR(u, 1, n + 1) { + to_erase.clear(); + for (auto v : F[u]) { + if (Guf.find(u) != Guf.find(v)) { + to_erase.insert(v); + F[v].erase(u); + } + } + ans += to_erase.size(); + for (auto e : to_erase) + F[u].erase(e); + } + + FOR(u, 1, n + 1) { + for (auto v : F[u]) + Fuf.join(u, v); + } + + FOR(u, 1, n + 1) { + for (auto v : G[u]) { + if (Fuf.find(u) != Fuf.find(v)) { + ++ans; + Fuf.join(u, v); + } + } + } + + dbgln(ans); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/998/e.in b/codeforces/998/e.in new file mode 100644 index 0000000..47ec446 --- /dev/null +++ b/codeforces/998/e.in @@ -0,0 +1,17 @@ +5 +3 2 1 +1 2 +2 3 +1 3 +2 1 1 +1 2 +1 2 +3 2 0 +3 2 +1 2 +1 0 0 +3 3 1 +1 2 +1 3 +2 3 +1 2 diff --git a/codeforces/998/e.out b/codeforces/998/e.out new file mode 100644 index 0000000..648c079 --- /dev/null +++ b/codeforces/998/e.out @@ -0,0 +1,8 @@ +3 +0 +2 +0 +2 + +[code]: 0 +[time]: 12.4309 ms \ No newline at end of file diff --git a/codeforces/998/f.cc b/codeforces/998/f.cc new file mode 100644 index 0000000..84ce822 --- /dev/null +++ b/codeforces/998/f.cc @@ -0,0 +1,109 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +constexpr int MOD = 998244353; + +void solve() { + ll k, n; + cin >> k >> n; + vec dp(k + 1); + dp[1] = n; + for (ll i = 2; i <= k; ++i) { + ll for_i = (n * (n + 1)) / 2 % MOD; + dp[i] = for_i; + for (ll factor = 2; factor < min(k, (ll)floorl(sqrtl(i))) + 1; ++factor) { + if (i % factor == 0) { + ll extra = (n * (n + 1) * (n - 1)) / 6 % MOD; + dp[i] = (dp[i] + extra) % MOD; + if (factor * factor != i) { + dp[i] = (dp[i] + extra) % MOD; + } + } + } + } + FOR(i, 1, k + 1) { + cout << dp[i] % MOD << " \n"[i == k]; + } +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/998/f.in b/codeforces/998/f.in new file mode 100644 index 0000000..d2e7004 --- /dev/null +++ b/codeforces/998/f.in @@ -0,0 +1,4 @@ +3 +2 2 +4 3 +10 6969420 diff --git a/codeforces/998/f.out b/codeforces/998/f.out new file mode 100644 index 0000000..6ebd22d --- /dev/null +++ b/codeforces/998/f.out @@ -0,0 +1,6 @@ +2 3 +3 6 6 10 +6969420 124188773 124188773 928542887 124188773 734652648 124188773 734652648 928542887 734652648 + +[code]: 0 +[time]: 4.03261 ms \ No newline at end of file diff --git a/codeforces/998/file.cc b/codeforces/998/file.cc new file mode 100644 index 0000000..8e749bd --- /dev/null +++ b/codeforces/998/file.cc @@ -0,0 +1,283 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int a = (b); (a) > (c); --(a)) + +#include +#include + +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template +struct custom_hash {}; + +template +inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) + hash_combine(value, x); + return value; + } +}; + +template +struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply( + [&value](T const &...args) { + (hash_combine(value, args), ...); + }, + a); + return value; + } +}; + +template +struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +struct union_find { + public: + union_find(size_t n) : par(n + 1), rank(n + 1, 0) { + for (size_t u = 0; u < n + 1; ++u) + par[u] = u; + }; + + void join(int u, int v) { + u = find(u), v = find(v); + + if (u == v) + return; + + if (rank[u] < rank[v]) + std::swap(u, v); + + if (rank[u] == rank[v]) + ++rank[u]; + + par[v] = u; + } + + int find(int u) { + if (u != par[u]) + par[u] = find(par[u]); + return par[u]; + } + + size_t capacity; + std::vector par; + std::vector rank; +}; + +vec> F, G; + +// TODO: union find reset method + +void solve() { + int n, m1, m2; + cin >> n >> m1 >> m2; + + F.assign(n + 1, unordered_set()); + G.assign(n + 1, unordered_set()); + + union_find Fuf(n + 1), Guf(n + 1); + + FOR(i, 0, m1) { + int u, v; + cin >> u >> v; + F[u].insert(v); + F[v].insert(u); + } + + FOR(i, 0, m2) { + int u, v; + cin >> u >> v; + G[u].insert(v); + G[v].insert(u); + Guf.join(u, v); + } + + int ans = 0; + + FOR(u, 1, n + 1) { + auto it = F[u].begin(); + while (it != F[u].end()) { + int v = *it; + if (Guf.find(u) != Guf.find(v)) { + ++ans; + F[u].erase(it++); + F[v].erase(u); + } else { + ++it; + } + } + } + + FOR(u, 1, n + 1) { + for (auto v : F[u]) + Fuf.join(u, v); + } + + FOR(u, 1, n + 1) { + for (auto v : G[u]) { + if (Fuf.find(u) != Fuf.find(v)) { + ++ans; + Fuf.join(u, v); + } + } + } + + dbgln(ans); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/998/temp/.clang-format b/codeforces/998/temp/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/998/temp/.clang-format @@ -0,0 +1,9 @@ +BasedOnStyle: Google +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: false +AllowShortLoopsOnASingleLine: false diff --git a/codeforces/998/temp/.clangd b/codeforces/998/temp/.clangd new file mode 100644 index 0000000..61f8494 --- /dev/null +++ b/codeforces/998/temp/.clangd @@ -0,0 +1,8 @@ +CompileFlags: + Add: + - -std=c++20 + - -Wall + - -Wextra + - -Wpedantic + - -Wshadow + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/codeforces/998/temp/a.cc b/codeforces/998/temp/a.cc new file mode 100644 index 0000000..d121d55 --- /dev/null +++ b/codeforces/998/temp/a.cc @@ -0,0 +1,88 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { + std::cout << '\n'; +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +void solve() { + dbgln("hi") +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/998/temp/a.in b/codeforces/998/temp/a.in new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/codeforces/998/temp/a.in @@ -0,0 +1 @@ +1 diff --git a/codeforces/998/temp/a.out b/codeforces/998/temp/a.out new file mode 100644 index 0000000..2a210a0 --- /dev/null +++ b/codeforces/998/temp/a.out @@ -0,0 +1,9 @@ +a.cc: In function ‘void solve()’: +a.cc:74:14: error: expected ‘;’ before ‘}’ token + 74 | dbgln("hi") + | ^ + | ; + 75 | } + | ~ + +[code]: 1 \ No newline at end of file diff --git a/codeforces/998/temp/b.cc b/codeforces/998/temp/b.cc new file mode 100644 index 0000000..dc08aac --- /dev/null +++ b/codeforces/998/temp/b.cc @@ -0,0 +1,74 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, std::make_format_args(args...)); +} + +template void dbg(T const &t) { std::cout << t; } + +template void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +void dbgln() { std::cout << '\n'; } + +template void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template void dbgln(T const &t) { + dbg(t); + cout << '\n'; +} + +template constexpr T MIN = std::numeric_limits::min(); + +template constexpr T MAX = std::numeric_limits::max(); + +template static T sc(auto &&x) { return static_cast(x); } + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +void solve() { + +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/998/temp/b.in b/codeforces/998/temp/b.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/998/temp/b.out b/codeforces/998/temp/b.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/998/temp/compile_flags.txt b/codeforces/998/temp/compile_flags.txt new file mode 100644 index 0000000..b5d4b68 --- /dev/null +++ b/codeforces/998/temp/compile_flags.txt @@ -0,0 +1,5 @@ +-std=c++20 +-Wall +-Wextra +-Wpedantic +-Wshadow