結果
問題 | No.2316 Freight Train |
ユーザー |
![]() |
提出日時 | 2023-03-14 21:53:13 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 75 ms / 2,000 ms |
コード長 | 419 bytes |
コンパイル時間 | 1,051 ms |
コンパイル使用メモリ | 99,024 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-18 09:22:39 |
合計ジャッジ時間 | 5,269 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include <iostream>#include <atcoder/dsu>using namespace std;int main() {cin.tie(nullptr);ios_base::sync_with_stdio(false);int N, Q;cin >> N >> Q;atcoder::dsu uf(N);for(int i = 0; i < N; i++) {int P;cin >> P;if(P != -1) uf.merge(i, --P);}while(Q--) {int A, B;cin >> A >> B;puts(uf.same(--A, --B) ? "Yes" : "No");}}