結果

問題 No.2316 Freight Train
ユーザー ttkkggwwttkkggww
提出日時 2023-05-26 21:31:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 299 ms / 2,000 ms
コード長 639 bytes
コンパイル時間 4,446 ms
コンパイル使用メモリ 262,364 KB
実行使用メモリ 6,480 KB
最終ジャッジ日時 2023-08-26 10:28:08
合計ジャッジ時間 12,633 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 293 ms
6,240 KB
testcase_04 AC 157 ms
4,736 KB
testcase_05 AC 109 ms
4,380 KB
testcase_06 AC 39 ms
4,376 KB
testcase_07 AC 265 ms
5,060 KB
testcase_08 AC 162 ms
5,408 KB
testcase_09 AC 219 ms
5,232 KB
testcase_10 AC 245 ms
5,168 KB
testcase_11 AC 192 ms
5,388 KB
testcase_12 AC 242 ms
5,792 KB
testcase_13 AC 292 ms
6,172 KB
testcase_14 AC 299 ms
6,388 KB
testcase_15 AC 294 ms
6,260 KB
testcase_16 AC 296 ms
6,192 KB
testcase_17 AC 298 ms
6,320 KB
testcase_18 AC 293 ms
6,184 KB
testcase_19 AC 291 ms
6,408 KB
testcase_20 AC 288 ms
6,172 KB
testcase_21 AC 293 ms
6,236 KB
testcase_22 AC 292 ms
6,304 KB
testcase_23 AC 268 ms
6,480 KB
testcase_24 AC 290 ms
6,316 KB
testcase_25 AC 276 ms
6,220 KB
testcase_26 AC 273 ms
6,180 KB
testcase_27 AC 248 ms
4,648 KB
testcase_28 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
int n,q;
vector<int> P;
vector<int> A,B;

void solve(){
	dsu UF(n);
	for(int i = 0;i<n;i++){
		if(P[i]<0)continue;
		UF.merge(i,P[i]);
	}
	for(int i = 0;i<q;i++){
		if(UF.same(A[i],B[i])){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n >> q;
	P = vector<int>(n);
	for(auto &i:P)cin >> i;
	for(auto &i:P)i--;
	A = B = vector<int>(q);
	for(int i = 0;i<q;i++){
		cin >> A[i] >> B[i];
	}
	for(auto &i:A)i--;
	for(auto &i:B)i--;
	solve();
}
0