結果
問題 | No.1565 Union |
ユーザー |
|
提出日時 | 2021-06-26 13:36:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 235 ms / 2,000 ms |
コード長 | 553 bytes |
コンパイル時間 | 2,271 ms |
コンパイル使用メモリ | 201,796 KB |
最終ジャッジ日時 | 2025-01-22 13:16:06 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include<bits/stdc++.h>#define int long longusing 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;}