結果

問題 No.2316 Freight Train
ユーザー 7iz67iz6
提出日時 2023-05-26 21:38:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 427 ms / 2,000 ms
コード長 330 bytes
コンパイル時間 2,614 ms
コンパイル使用メモリ 143,120 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-26 10:44:50
合計ジャッジ時間 13,595 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 400 ms
4,380 KB
testcase_04 AC 218 ms
4,376 KB
testcase_05 AC 152 ms
4,376 KB
testcase_06 AC 52 ms
4,376 KB
testcase_07 AC 349 ms
4,380 KB
testcase_08 AC 227 ms
4,376 KB
testcase_09 AC 304 ms
4,500 KB
testcase_10 AC 333 ms
4,376 KB
testcase_11 AC 275 ms
4,376 KB
testcase_12 AC 338 ms
4,380 KB
testcase_13 AC 397 ms
4,376 KB
testcase_14 AC 427 ms
4,376 KB
testcase_15 AC 401 ms
4,380 KB
testcase_16 AC 403 ms
4,376 KB
testcase_17 AC 423 ms
4,384 KB
testcase_18 AC 404 ms
4,380 KB
testcase_19 AC 406 ms
4,376 KB
testcase_20 AC 403 ms
4,380 KB
testcase_21 AC 405 ms
4,376 KB
testcase_22 AC 393 ms
4,376 KB
testcase_23 AC 373 ms
4,380 KB
testcase_24 AC 383 ms
4,376 KB
testcase_25 AC 372 ms
4,380 KB
testcase_26 AC 386 ms
4,376 KB
testcase_27 AC 290 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<atcoder/all>
using namespace std;

int main() {
	int N, Q;
	cin >> N >> Q;
	atcoder::dsu uf(N);
	for(int i = 0; i < N; i++) {
		int u;
		cin >> u;
		if(u == -1) continue;
		else {
			uf.merge(i, u-1);
		}
	}
	
	while(Q--) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		cout << (uf.same(u, v) ? "Yes" : "No") << endl;
	}
}
0