結果

問題 No.2910 単体ホモロジー入門
ユーザー ルクルク
提出日時 2024-10-04 21:44:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,987 bytes
コンパイル時間 7,586 ms
コンパイル使用メモリ 319,752 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-04 21:44:53
合計ジャッジ時間 7,237 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,816 KB
testcase_03 AC 2 ms
6,820 KB
testcase_04 AC 2 ms
6,820 KB
testcase_05 AC 2 ms
6,816 KB
testcase_06 AC 1 ms
6,816 KB
testcase_07 AC 2 ms
6,820 KB
testcase_08 AC 1 ms
6,820 KB
testcase_09 AC 1 ms
6,820 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
6,820 KB
testcase_24 AC 2 ms
6,824 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1 ms
6,816 KB
testcase_28 AC 2 ms
6,816 KB
testcase_29 WA -
testcase_30 AC 2 ms
6,820 KB
testcase_31 AC 2 ms
6,816 KB
testcase_32 WA -
testcase_33 AC 2 ms
6,820 KB
testcase_34 AC 1 ms
6,816 KB
testcase_35 AC 2 ms
6,816 KB
testcase_36 AC 1 ms
6,816 KB
testcase_37 AC 2 ms
6,816 KB
testcase_38 AC 2 ms
6,816 KB
testcase_39 AC 1 ms
6,816 KB
testcase_40 WA -
testcase_41 AC 2 ms
6,816 KB
testcase_42 AC 2 ms
6,820 KB
testcase_43 WA -
testcase_44 AC 2 ms
6,820 KB
testcase_45 WA -
testcase_46 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#include <chrono>
#include <unistd.h>
using namespace std;
using namespace chrono;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = n; i > 0; --i)
#define bitrep(i, n) for (ll i = 0; i < (1 << n); ++i)
#define all(a) (a).begin(), (a).end()
#define yesNo(b) ((b) ? "Yes" : "No")
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using mint = modint998244353;
using MINT = modint1000000007;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
constexpr double pi = 3.141592653589793;
constexpr ll smallMOD = 998244353;
constexpr ll bigMOD = 1000000007;
constexpr ll dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr ll dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Init
{
    Init()
    {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(15);
    }
} init;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
    os << "[";
    rep(i, vec.size())
    {
        os << vec[i];
        if (i != vec.size() - 1)
            os << ", ";
    }
    os << "]";
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &vec)
{
    os << "[";
    rep(i, vec.size())
    {
        os << vec[i];
        if (i != vec.size() - 1)
            os << ", ";
    }
    os << "]";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var)
{
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &st)
{
    os << "{";
    for (auto itr = st.begin(); itr != st.end(); ++itr)
    {
        os << *itr;
        if (next(itr) != st.end())
            os << ", ";
    }
    os << "}";
    return os;
}

// graph_template
struct Edge
{
    ll to;
    ll cost;
    Edge(ll to, ll cost) : to(to), cost(cost) {}
    bool operator>(const Edge &e) const
    {
        return cost > e.cost;
    }
};

struct Graph
{
    vector<vector<Edge>> g;
    Graph(ll n)
    {
        g.resize(n);
    }
    ll size()
    {
        return g.size();
    }
    void add_edge(ll from, ll to, ll cost = 1)
    {
        g[from].push_back(Edge(to, cost));
        g[to].push_back(Edge(from, cost));
    }
    void add_directed_edge(ll from, ll to, ll cost = 1)
    {
        g[from].push_back(Edge(to, cost));
    }
    pair<ll, vector<ll>> tree_diameter()
    {
        function<pair<ll, ll>(ll, ll)> dfs = [&](ll v, ll p) -> pair<ll, ll>
        {
            pair<ll, ll> res = {0, v};
            for (auto e : g[v])
            {
                if (e.to == p)
                    continue;
                auto [d, u] = dfs(e.to, v);
                d += e.cost;
                if (res.first < d)
                {
                    res.first = d;
                    res.second = u;
                }
            }
            return res;
        };
        auto [d, u] = dfs(0, -1);
        auto [d2, v] = dfs(u, -1);
        vector<ll> path;
        function<void(ll, ll, ll)> get_path = [&](ll v, ll p, ll u)
        {
            if (v == u)
            {
                path.push_back(v);
                return;
            }
            for (auto e : g[v])
            {
                if (e.to == p)
                    continue;
                get_path(e.to, v, u);
                if (!path.empty())
                {
                    path.push_back(v);
                    return;
                }
            }
        };
        get_path(u, -1, v);
        return {d2, path};
    }
    vector<vector<ll>> get_all_closed_circuit()
    {
        // グラフ上のすべての閉路のパスを返す
        vector<vector<ll>> res;
        vector<ll> path;
        vector<ll> used(g.size(), 0);
        function<void(ll, ll)> dfs = [&](ll v, ll p) -> void
        {
            used[v] = 1;
            path.push_back(v);
            for (auto e : g[v])
            {
                if (e.to == p)
                    continue;
                if (used[e.to] == 1)
                {
                    // 閉路を検出
                    vector<ll> cycle;
                    for (ll i = path.size() - 1; i >= 0; --i)
                    {
                        cycle.push_back(path[i]);
                        if (path[i] == e.to)
                            break;
                    }
                    res.push_back(cycle);
                }
                else if (used[e.to] == 0)
                {
                    dfs(e.to, v);
                }
            }
            path.pop_back();
            used[v] = 2;
        };
        dfs(0, -1);
        return res;
    }
    vector<Edge> &operator[](ll v)
    {
        return g[v];
    }
};

int main()
{
    ll n, m;
    cin >> n >> m;
    Graph g(n);
    rep(i, m)
    {
        ll u, v;
        cin >> u >> v;
        g.add_edge(u, v);
    }
    auto all_path = g.get_all_closed_circuit();
    set<ll> t;
    rep(i, 3)
    {
        ll x;
        cin >> x;
        t.insert(x);
    }
    for (auto path : all_path)
    {
        bool f = false;
        set<ll> s;
        for (auto v : path)
        {
            s.insert(v);
        }
        // sとtの比較.
        for (auto v : t)
        {
            if (s.find(v) == s.end())
            {
                f = true;
                break;
            }
        }
        for (auto v : s)
        {
            if (t.find(v) == t.end())
            {
                f = true;
                break;
            }
        }
        if (!f)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}
0