結果

問題 No.2316 Freight Train
ユーザー nonon
提出日時 2024-01-08 13:02:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 423 bytes
コンパイル時間 2,279 ms
コンパイル使用メモリ 197,004 KB
最終ジャッジ日時 2025-02-18 16:31:06
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/dsu>
using namespace std;
int N,Q;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>N>>Q;
    atcoder::dsu uf(N);
    for(int i=0;i<N;i++)
    {
        int p;
        cin>>p;
        p--;
        if(p>=0)uf.merge(i,p);
    }
    while(Q--)
    {
        int u,v;
        cin>>u>>v;
        u--,v--;
        cout << (uf.same(u,v)?"Yes\n":"No\n");
    }
}
0