結果

問題 No.3093 Safe Infection
ユーザー RiRinbaru
提出日時 2025-03-04 03:30:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 1,726 bytes
コンパイル時間 4,671 ms
コンパイル使用メモリ 234,276 KB
実行使用メモリ 18,168 KB
最終ジャッジ日時 2025-04-13 19:21:48
合計ジャッジ時間 12,490 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 71
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, p, n) for (ll i = p; i < (ll)(n); i++)
#define rep2(i, p, n) for (ll i = p; i >= (ll)(n); i--)
using namespace std;
using ll = long long;
using ld = long double;
const double pi = 3.141592653589793;
const long long inf = 2 * 1e9;
const long long linf = 4 * 1e18;
const ll mod1 = 1000000007;
const ll mod2 = 998244353;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

// atcoder
#include <atcoder/all>
using namespace atcoder;
using mint1 = modint1000000007;
using mint2 = modint998244353;

vector<pair<ll, ll>> base = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int main()
{
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N);
    vector<pair<ll, ll>> li(N);
    rep(i, 0, N)
    {
        cin >> A.at(i);
        li.at(i) = {A.at(i), i};
    }
    sort(li.begin(), li.end());
    vector<vector<ll>> G(N);
    rep(i, 0, M)
    {
        ll u, v;
        cin >> u >> v;
        u--;
        v--;
        G.at(u).push_back(v);
        G.at(v).push_back(u);
    }
    dsu D(N);
    rep(i, 0, N)
    {
        for (ll c : G.at(li.at(i).second))
        {
            if (A.at(D.leader(li.at(i).second)) >= A.at(D.leader(c)) && A.at(D.leader(li.at(i).second)) - A.at(D.leader(c)) <= K)
            {
                A.at(D.leader(c)) = A.at(D.leader(li.at(i).second));
                D.merge(li.at(i).second, c);
            }
        }
    }
    if (D.groups().size() == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}
0