結果

問題 No.2316 Freight Train
ユーザー VvyLwVvyLw
提出日時 2023-05-26 23:44:07
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 305 bytes
コンパイル時間 840 ms
コンパイル使用メモリ 99,156 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-26 14:03:19
合計ジャッジ時間 11,681 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 403 ms
4,376 KB
testcase_04 AC 214 ms
4,380 KB
testcase_05 AC 153 ms
4,380 KB
testcase_06 AC 52 ms
4,384 KB
testcase_07 AC 338 ms
4,376 KB
testcase_08 AC 229 ms
4,380 KB
testcase_09 AC 292 ms
4,380 KB
testcase_10 AC 321 ms
4,380 KB
testcase_11 AC 285 ms
4,380 KB
testcase_12 AC 326 ms
4,388 KB
testcase_13 AC 399 ms
4,380 KB
testcase_14 AC 395 ms
4,380 KB
testcase_15 AC 405 ms
4,376 KB
testcase_16 AC 394 ms
4,380 KB
testcase_17 AC 407 ms
4,376 KB
testcase_18 AC 405 ms
4,376 KB
testcase_19 AC 395 ms
4,380 KB
testcase_20 AC 392 ms
4,380 KB
testcase_21 AC 400 ms
4,380 KB
testcase_22 AC 402 ms
4,380 KB
testcase_23 AC 359 ms
4,380 KB
testcase_24 AC 385 ms
4,380 KB
testcase_25 AC 362 ms
4,380 KB
testcase_26 AC 367 ms
4,384 KB
testcase_27 AC 286 ms
4,384 KB
testcase_28 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;

int main() {
	int n,q; cin>>n>>q;
	dsu uf(n+1);
	for(int i=1; i<=n; ++i) {
		int p; cin>>p;
		if(p==-1) continue;
		uf.merge(i,p);
	}
	while(q--) {
		int a,b; cin>>a>>b;
		cout<<(uf.same(a,b)?"Yes":"No")<<'\n';
	}
}
0