結果
問題 | No.2664 Prime Sum |
ユーザー | OnjoujiToki |
提出日時 | 2024-03-08 22:14:08 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 8,577 bytes |
コンパイル時間 | 1,397 ms |
コンパイル使用メモリ | 138,476 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-09-29 19:46:04 |
合計ジャッジ時間 | 2,512 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 37 |
ソースコード
#include <algorithm>#include <array>#include <bitset>#include <cassert>#include <chrono>#include <cmath>#include <complex>#include <cstdint>#include <cstring>#include <ctime>#include <deque>#include <functional>#include <iomanip>#include <iostream>#include <iterator>#include <map>#include <numeric>#include <queue>#include <random>#include <set>#include <stack>#include <unordered_map>#include <unordered_set>#include <vector>template <typename T1, typename T2>std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p) {os << p.first << " " << p.second;return os;}template <typename T1, typename T2>std::istream &operator>>(std::istream &is, std::pair<T1, T2> &p) {is >> p.first >> p.second;return is;}template <typename T>std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {for (int i = 0; i < (int)v.size(); i++) {os << v[i] << (i + 1 != (int)v.size() ? " " : "");}return os;}template <typename T>std::istream &operator>>(std::istream &is, std::vector<T> &v) {for (T &in : v) is >> in;return is;}template <int mod>struct ModInt {int x;ModInt() : x(0) {}ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}ModInt &operator+=(const ModInt &p) {if ((x += p.x) >= mod) x -= mod;return *this;}ModInt &operator-=(const ModInt &p) {if ((x += mod - p.x) >= mod) x -= mod;return *this;}ModInt &operator*=(const ModInt &p) {x = (int)(1LL * x * p.x % mod);return *this;}ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}ModInt &operator^=(long long p) { // quick_pow here:3ModInt res = 1;for (; p; p >>= 1) {if (p & 1) res *= *this;*this *= *this;}return *this = res;}ModInt operator-() const { return ModInt(-x); }ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }ModInt operator^(long long p) const { return ModInt(*this) ^= p; }bool operator==(const ModInt &p) const { return x == p.x; }bool operator!=(const ModInt &p) const { return x != p.x; }explicit operator int() const { return x; } // added by QCFiumModInt operator=(const int p) {x = p;return ModInt(*this);} // added by QCFiumModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;while (b > 0) {t = a / b;a -= t * b;std::swap(a, b);u -= t * v;std::swap(u, v);}return ModInt(u);}friend std::ostream &operator<<(std::ostream &os, const ModInt<mod> &p) {return os << p.x;}friend std::istream &operator>>(std::istream &is, ModInt<mod> &a) {long long x;is >> x;a = ModInt<mod>(x);return (is);}};using mint = ModInt<998244353>;const int MOD = 998244353;template <typename T>std::pair<std::vector<T>, std::vector<T>> get_prime_factor_with_kinds(T n) {std::vector<T> prime_factors;std::vector<T> cnt; // number of i_th factorfor (T i = 2; i * i <= n; i++) {if (n % i == 0) {prime_factors.push_back(i);cnt.push_back(0);while (n % i == 0) n /= i, cnt[(int)prime_factors.size() - 1]++;}}if (n > 1) prime_factors.push_back(n), cnt.push_back(1);assert(prime_factors.size() == cnt.size());return {prime_factors, cnt};}template <typename T>std::vector<T> get_divisors(T x, bool sorted = true) {std::vector<T> res;for (T i = 1; i <= x / i; i++)if (x % i == 0) {res.push_back(i);if (i != x / i) res.push_back(x / i);}if (sorted) std::sort(res.begin(), res.end());return res;}// source atcoder#ifdef _MSC_VER#include <intrin.h>#endif#if __cplusplus >= 202002L#include <bit>#endifnamespace atcoder {namespace internal {#if __cplusplus >= 202002Lusing std::bit_ceil;#elseunsigned int bit_ceil(unsigned int n) {unsigned int x = 1;while (x < (unsigned int)(n)) x *= 2;return x;}#endifint countr_zero(unsigned int n) {#ifdef _MSC_VERunsigned long index;_BitScanForward(&index, n);return index;#elsereturn __builtin_ctz(n);#endif}constexpr int countr_zero_constexpr(unsigned int n) {int x = 0;while (!(n & (1 << x))) x++;return x;}} // namespace internal} // namespace atcodernamespace atcoder {#if __cplusplus >= 201703Ltemplate <class S, auto op, auto e>struct segtree {static_assert(std::is_convertible_v<decltype(op), std::function<S(S, S)>>,"op must work as S(S, S)");static_assert(std::is_convertible_v<decltype(e), std::function<S()>>,"e must work as S()");#elsetemplate <class S, S (*op)(S, S), S (*e)()>struct segtree {#endifpublic:segtree() : segtree(0) {}explicit segtree(int n) : segtree(std::vector<S>(n, e())) {}explicit segtree(const std::vector<S> &v) : _n(int(v.size())) {size = (int)internal::bit_ceil((unsigned int)(_n));log = internal::countr_zero((unsigned int)size);d = std::vector<S>(2 * size, e());for (int i = 0; i < _n; i++) d[size + i] = v[i];for (int i = size - 1; i >= 1; i--) {update(i);}}void set(int p, S x) {assert(0 <= p && p < _n);p += size;d[p] = x;for (int i = 1; i <= log; i++) update(p >> i);}S get(int p) const {assert(0 <= p && p < _n);return d[p + size];}S prod(int l, int r) const {assert(0 <= l && l <= r && r <= _n);S sml = e(), smr = e();l += size;r += size;while (l < r) {if (l & 1) sml = op(sml, d[l++]);if (r & 1) smr = op(d[--r], smr);l >>= 1;r >>= 1;}return op(sml, smr);}S all_prod() const { return d[1]; }template <bool (*f)(S)>int max_right(int l) const {return max_right(l, [](S x) { return f(x); });}template <class F>int max_right(int l, F f) const {assert(0 <= l && l <= _n);assert(f(e()));if (l == _n) return _n;l += size;S sm = e();do {while (l % 2 == 0) l >>= 1;if (!f(op(sm, d[l]))) {while (l < size) {l = (2 * l);if (f(op(sm, d[l]))) {sm = op(sm, d[l]);l++;}}return l - size;}sm = op(sm, d[l]);l++;} while ((l & -l) != l);return _n;}template <bool (*f)(S)>int min_left(int r) const {return min_left(r, [](S x) { return f(x); });}template <class F>int min_left(int r, F f) const {assert(0 <= r && r <= _n);assert(f(e()));if (r == 0) return 0;r += size;S sm = e();do {r--;while (r > 1 && (r % 2)) r >>= 1;if (!f(op(d[r], sm))) {while (r < size) {r = (2 * r + 1);if (f(op(d[r], sm))) {sm = op(d[r], sm);r--;}}return r + 1 - size;}sm = op(d[r], sm);} while ((r & -r) != r);return 0;}private:int _n, size, log;std::vector<S> d;void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }};} // namespace atcodertemplate <typename T>struct DSU {std::vector<T> f, siz;DSU(int n) : f(n), siz(n, 1) { std::iota(f.begin(), f.end(), 0); }T leader(T x) {while (x != f[x]) x = f[x] = f[f[x]];return x;}bool same(T x, T y) { return leader(x) == leader(y); }bool merge(T x, T y) {x = leader(x);y = leader(y);if (x == y) return false;siz[x] += siz[y];f[y] = x;return true;}T size(int x) { return siz[leader(x)]; }};void solve() {int n, m;std::cin >> n >> m;std::vector<std::vector<int>> g(n);for (int i = 0; i < m; i++) {int a, b;std::cin >> a >> b;a--, b--;g[a].push_back(b);g[b].push_back(a);}std::vector<int> color(n, -1);std::vector<int> ans;std::function<void(int, int)> dfs = [&](int u, int c) {color[u] = c;for (int v : g[u]) {if (color[v] == -1) {dfs(v, c ^ 1);} else if (color[v] == c) {std::cout << "No" << std::endl;exit(0);}}};for (int i = 0; i < n; i++) {if (color[i] == -1) {dfs(i, 0);}}std::cout << "Yes" << '\n';}int main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);int t = 1;// std::cin >> t;while (t--) {solve();}}