結果

問題 No.1565 Union
ユーザー shiomusubi496shiomusubi496
提出日時 2021-06-26 13:36:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 2,018 ms
コンパイル使用メモリ 208,040 KB
実行使用メモリ 16,740 KB
最終ジャッジ日時 2023-09-07 16:31:47
合計ジャッジ時間 6,294 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 62 ms
6,600 KB
testcase_11 AC 104 ms
12,888 KB
testcase_12 AC 118 ms
9,172 KB
testcase_13 AC 36 ms
6,012 KB
testcase_14 AC 141 ms
12,012 KB
testcase_15 AC 189 ms
16,740 KB
testcase_16 AC 176 ms
16,320 KB
testcase_17 AC 181 ms
16,572 KB
testcase_18 AC 203 ms
16,396 KB
testcase_19 AC 195 ms
16,452 KB
testcase_20 AC 136 ms
15,644 KB
testcase_21 AC 138 ms
15,700 KB
testcase_22 AC 137 ms
15,664 KB
testcase_23 AC 137 ms
15,680 KB
testcase_24 AC 138 ms
15,592 KB
testcase_25 AC 140 ms
15,632 KB
testcase_26 AC 137 ms
15,588 KB
testcase_27 AC 137 ms
15,576 KB
testcase_28 AC 139 ms
15,572 KB
testcase_29 AC 138 ms
15,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int N,M; cin>>N>>M;
    vector<vector<int>> G(N);
    for(int i=0;i<M;i++){
        int a,b; cin>>a>>b;
        G[--a].push_back(--b);
        G[b].push_back(a);
    }
    vector<int> dist(N,-1); dist[0]=0;
    queue<int> Q; Q.push(0);
    while(!Q.empty()){
        int v=Q.front(); Q.pop();
        for(int t:G[v]){
            if(dist[t]==-1){
                dist[t]=dist[v]+1;
                Q.push(t);
            }
        }
    }
    cout<<dist[N-1]<<endl;
}
0