結果

問題 No.1565 Union
ユーザー SSRSSSRS
提出日時 2021-06-26 13:04:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 508 bytes
コンパイル時間 1,648 ms
コンパイル使用メモリ 173,356 KB
実行使用メモリ 14,992 KB
最終ジャッジ日時 2023-09-07 16:16:21
合計ジャッジ時間 6,566 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 59 ms
5,156 KB
testcase_11 AC 102 ms
11,424 KB
testcase_12 AC 112 ms
6,492 KB
testcase_13 AC 37 ms
5,368 KB
testcase_14 AC 137 ms
9,844 KB
testcase_15 AC 185 ms
14,324 KB
testcase_16 AC 171 ms
14,064 KB
testcase_17 AC 177 ms
14,360 KB
testcase_18 AC 184 ms
14,516 KB
testcase_19 AC 180 ms
14,328 KB
testcase_20 AC 136 ms
14,992 KB
testcase_21 AC 136 ms
14,852 KB
testcase_22 AC 135 ms
14,796 KB
testcase_23 AC 136 ms
14,880 KB
testcase_24 AC 136 ms
14,920 KB
testcase_25 AC 137 ms
14,804 KB
testcase_26 AC 136 ms
14,824 KB
testcase_27 AC 137 ms
14,848 KB
testcase_28 AC 139 ms
14,816 KB
testcase_29 AC 137 ms
14,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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