結果

問題 No.2316 Freight Train
ユーザー VvyLw
提出日時 2023-05-26 23:44:07
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 460 ms / 2,000 ms
コード長 305 bytes
コンパイル時間 1,174 ms
コンパイル使用メモリ 99,536 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-25 11:18:25
合計ジャッジ時間 13,138 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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