提出 #71482794


ソースコード 拡げる

#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
 
#ifndef ONLINE_JUDGE
#include "debug.h"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <class T> void output(vector < T > & a) { for (auto & x: a) {cout << x << ' ';}cout << '\n';}


 
// Golden Rules
/*
    Solutions are simple.
 
    Proofs are simple.
 
    Implementations are simple.
 
                         ~ TEJA DRONADULA SIR!!
*/



void solve() {
     int n, m;
     cin >> n >> m;
     vector<vector<int>> adj(n);
     for (int i = 0; i < m; ++i) {
          int u, v;
          cin >> u >> v;
          --u, --v;
          adj[v].push_back(u);
     }
     vector<int> s(n);
     int q;
     cin >> q;
     while (q--) {
          int t, v;
          cin >> t >> v;
          --v;
          if (t == 1) {
               queue<int> q;
               q.push(v);
               while (!q.empty()) {
                    int x = q.front();
                    q.pop();
                    if (s[x]) continue;
                    s[x] = 1;
                    for (auto &y : adj[x]) {
                         if (s[y] == 0) {
                              q.push(y);
                         }
                    }
               }
          }    
          else {
               cout << (s[v] ? "Yes" : "No") << "\n";
          }
     }    
} 



int32_t main() {
     ios::sync_with_stdio(false);
     cin.tie(nullptr);
 
     #ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
          freopen("error.txt", "w", stderr);
     #endif

     int t = 1;
     // cin >> t; 


     for (int cases = 1; cases <= t; ++cases) {
          solve();
     }
 
     #ifndef ONLINE_JUDGE
          double T = 1000.0 * clock() / CLOCKS_PER_SEC;
          cout << "\n[Finished in " << T << "ms]";
          cerr << "\n[Finished in " << T << "ms]";
     #endif
 
     return 0;
}

提出情報

提出日時
問題 D - Reachability Query 2
ユーザ Gokuu007
言語 C++23 (GCC 15.2.0)
得点 425
コード長 2166 Byte
結果 AC
実行時間 98 ms
メモリ 22276 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 3420 KiB
random_01.txt AC 78 ms 18852 KiB
random_02.txt AC 75 ms 19008 KiB
random_03.txt AC 44 ms 8584 KiB
random_04.txt AC 60 ms 10752 KiB
random_05.txt AC 24 ms 4164 KiB
random_06.txt AC 21 ms 3788 KiB
random_07.txt AC 31 ms 6016 KiB
random_08.txt AC 76 ms 16572 KiB
random_09.txt AC 30 ms 5632 KiB
random_10.txt AC 32 ms 5824 KiB
random_11.txt AC 57 ms 9424 KiB
random_12.txt AC 85 ms 17720 KiB
random_13.txt AC 30 ms 6088 KiB
random_14.txt AC 27 ms 5176 KiB
random_15.txt AC 52 ms 10612 KiB
random_16.txt AC 63 ms 11588 KiB
random_17.txt AC 50 ms 17468 KiB
random_18.txt AC 69 ms 22220 KiB
random_19.txt AC 21 ms 3600 KiB
random_20.txt AC 27 ms 5072 KiB
random_21.txt AC 74 ms 18508 KiB
random_22.txt AC 78 ms 22184 KiB
random_23.txt AC 53 ms 19832 KiB
random_24.txt AC 72 ms 22244 KiB
random_25.txt AC 98 ms 22072 KiB
random_26.txt AC 96 ms 22220 KiB
random_27.txt AC 75 ms 22276 KiB
random_28.txt AC 51 ms 17524 KiB
sample_01.txt AC 1 ms 3432 KiB