結果

問題 No.1565 Union
ユーザー 👑 NachiaNachia
提出日時 2021-06-26 13:09:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 983 ms
コンパイル使用メモリ 78,328 KB
実行使用メモリ 15,900 KB
最終ジャッジ日時 2023-09-07 16:20:12
合計ジャッジ時間 4,272 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 25 ms
5,204 KB
testcase_11 AC 60 ms
11,964 KB
testcase_12 AC 51 ms
6,696 KB
testcase_13 AC 18 ms
5,600 KB
testcase_14 AC 71 ms
10,240 KB
testcase_15 AC 110 ms
15,076 KB
testcase_16 AC 102 ms
14,232 KB
testcase_17 AC 116 ms
15,232 KB
testcase_18 AC 116 ms
15,092 KB
testcase_19 AC 113 ms
15,156 KB
testcase_20 AC 62 ms
15,760 KB
testcase_21 AC 61 ms
15,772 KB
testcase_22 AC 61 ms
15,756 KB
testcase_23 AC 60 ms
15,900 KB
testcase_24 AC 60 ms
15,828 KB
testcase_25 AC 63 ms
15,756 KB
testcase_26 AC 61 ms
15,828 KB
testcase_27 AC 62 ms
15,832 KB
testcase_28 AC 62 ms
15,896 KB
testcase_29 AC 62 ms
15,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)


int N,M;
vector<vector<int>> E;

int main(){
  cin >> N >> M;
  E.resize(N);
  rep(i,M){
    int a,b; cin >> a >> b; a--; b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  vector<int> D(N,-1);
  vector<int> I;
  D[0] = 0;
  I.push_back(0);
  rep(i,I.size()){
    int p = I[i];
    for(int e : E[p]) if(D[e] == -1){
      D[e] = D[p] + 1;
      I.push_back(e);
    }
  }

  cout << D[N-1] << "\n";
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_inst;
0