提出 #71496334


ソースコード 拡げる

#include <bits/stdc++.h>

#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define int long long
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int INF = 1010000000000000017LL;
static const double eps = 1e-12;
static const double pi = 3.14159265358979323846;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
static const int ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};

template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int N, M, Q;

signed main() {
    cin >> N >> M;
    vector<vector<int>> A(N);
    for (int i = 0; i < M; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        A[v].push_back(u);
    }
    cin >> Q;
    vector<bool> visited(N, false);
    while (Q--) {
        int q, v;
        cin >> q >> v;
        v--;
        if (q == 1) {
            if (!visited[v]) {
                visited[v] = true;
                queue<int> que;
                que.push(v);
                while (que.size() > 0) {
                    int q = que.front();
                    que.pop();
                    for (auto u : A[q]) {
                        if (visited[u]) {
                            continue;
                        }
                        visited[u] = true;
                        que.push(u);
                    }
                }
            }
        } else {
            if (visited[v]) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        }
    }
}

提出情報

提出日時
問題 D - Reachability Query 2
ユーザ tsuyosshi
言語 C++23 (GCC 15.2.0)
得点 425
コード長 2002 Byte
結果 AC
実行時間 362 ms
メモリ 19848 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 425 / 425
結果
AC × 1
AC × 30
セット名 テストケース
Sample sample_01.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, sample_01.txt
ケース名 結果 実行時間 メモリ
min.txt AC 1 ms 3556 KiB
random_01.txt AC 338 ms 16552 KiB
random_02.txt AC 337 ms 16684 KiB
random_03.txt AC 249 ms 7852 KiB
random_04.txt AC 300 ms 9692 KiB
random_05.txt AC 173 ms 4076 KiB
random_06.txt AC 160 ms 3664 KiB
random_07.txt AC 211 ms 5492 KiB
random_08.txt AC 340 ms 14668 KiB
random_09.txt AC 154 ms 5128 KiB
random_10.txt AC 165 ms 5624 KiB
random_11.txt AC 240 ms 8548 KiB
random_12.txt AC 310 ms 15752 KiB
random_13.txt AC 117 ms 5560 KiB
random_14.txt AC 101 ms 4716 KiB
random_15.txt AC 178 ms 9384 KiB
random_16.txt AC 204 ms 10532 KiB
random_17.txt AC 305 ms 15140 KiB
random_18.txt AC 327 ms 19788 KiB
random_19.txt AC 163 ms 3648 KiB
random_20.txt AC 192 ms 4780 KiB
random_21.txt AC 330 ms 16164 KiB
random_22.txt AC 326 ms 19756 KiB
random_23.txt AC 306 ms 17320 KiB
random_24.txt AC 328 ms 19720 KiB
random_25.txt AC 362 ms 19748 KiB
random_26.txt AC 352 ms 19848 KiB
random_27.txt AC 289 ms 19848 KiB
random_28.txt AC 256 ms 15136 KiB
sample_01.txt AC 1 ms 3368 KiB