結果
| 問題 |
No.2316 Freight Train
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-26 21:48:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 831 bytes |
| コンパイル時間 | 3,140 ms |
| コンパイル使用メモリ | 158,768 KB |
| 最終ジャッジ日時 | 2025-02-13 06:23:40 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 MLE * 1 |
| other | AC * 6 MLE * 20 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cstring>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)
vector<int> par;
int find(int x){
if (par[x] == -x){
return x;
}
else{
return par[x] = find(par[x]);
}
}
int main(){
int n,q;
cin >> n >> q;
par.resize(n);
vector<int> a(n);
rep(i,n){
int x;
cin >> x;
if (x == -1){
par[i] = -i;
}
else par[i] = x-1;
}
rep(i,n){
par[i] = find(i);
}
rep(i,q){
int a,b;
cin >> a >> b;
if (par[a-1] == par[b-1]){
cout << "Yes\n";
}
else cout << "No\n";
}
return 0;
}