結果

問題 No.1565 Union
ユーザー MZKiMZKi
提出日時 2021-06-26 13:23:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 1,110 bytes
コンパイル時間 1,330 ms
コンパイル使用メモリ 151,012 KB
実行使用メモリ 15,064 KB
最終ジャッジ日時 2023-09-07 16:28:25
合計ジャッジ時間 5,644 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 58 ms
5,128 KB
testcase_11 AC 102 ms
11,432 KB
testcase_12 AC 112 ms
6,616 KB
testcase_13 AC 35 ms
5,196 KB
testcase_14 AC 138 ms
9,892 KB
testcase_15 AC 177 ms
14,436 KB
testcase_16 AC 169 ms
14,144 KB
testcase_17 AC 187 ms
14,196 KB
testcase_18 AC 189 ms
14,476 KB
testcase_19 AC 190 ms
14,436 KB
testcase_20 AC 135 ms
15,064 KB
testcase_21 AC 135 ms
14,892 KB
testcase_22 AC 134 ms
14,748 KB
testcase_23 AC 132 ms
14,940 KB
testcase_24 AC 134 ms
14,964 KB
testcase_25 AC 136 ms
14,844 KB
testcase_26 AC 134 ms
14,840 KB
testcase_27 AC 136 ms
14,776 KB
testcase_28 AC 136 ms
14,840 KB
testcase_29 AC 134 ms
14,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

using Graph = vector<vector<int>>;

int main(){
    int n, m;
    cin >> n >> m;
    Graph G(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }    
    vector<int> d(n, -1);
    d[0] = 0;
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(auto nv : G[v]){
            if(d[nv] == -1){
                d[nv] = d[v] + 1;
                que.push(nv);
            }
        }
    }
    cout << d[n-1] << endl;
}
0