結果

問題 No.2316 Freight Train
ユーザー yansi819yansi819
提出日時 2024-04-08 11:32:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 490 ms / 2,000 ms
コード長 445 bytes
コンパイル時間 4,567 ms
コンパイル使用メモリ 263,564 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 11:33:17
合計ジャッジ時間 19,143 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 490 ms
6,676 KB
testcase_04 AC 244 ms
6,676 KB
testcase_05 AC 178 ms
6,676 KB
testcase_06 AC 58 ms
6,676 KB
testcase_07 AC 393 ms
6,676 KB
testcase_08 AC 286 ms
6,676 KB
testcase_09 AC 343 ms
6,676 KB
testcase_10 AC 369 ms
6,676 KB
testcase_11 AC 327 ms
6,676 KB
testcase_12 AC 388 ms
6,676 KB
testcase_13 AC 466 ms
6,676 KB
testcase_14 AC 484 ms
6,676 KB
testcase_15 AC 462 ms
6,676 KB
testcase_16 AC 488 ms
6,676 KB
testcase_17 AC 470 ms
6,676 KB
testcase_18 AC 463 ms
6,676 KB
testcase_19 AC 483 ms
6,676 KB
testcase_20 AC 462 ms
6,676 KB
testcase_21 AC 478 ms
6,676 KB
testcase_22 AC 467 ms
6,676 KB
testcase_23 AC 422 ms
6,676 KB
testcase_24 AC 457 ms
6,676 KB
testcase_25 AC 429 ms
6,676 KB
testcase_26 AC 425 ms
6,676 KB
testcase_27 AC 321 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int main() {
  int N, Q; cin >> N >> Q;
  dsu uf(N);
  for (int i = 0; i < N; i++) {
    int p; cin >> p; p--;
    if (p >= 0) uf.merge(i, p);
  }
  while (Q--) {
    int a, b; cin >> a >> b;
    a--, b--;
    cout << (uf.same(a, b) ? "Yes": "No") << endl;
  }
  return 0;
}
0