結果
問題 | No.1565 Union |
ユーザー | ytqm3 |
提出日時 | 2021-06-26 14:31:00 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 203 ms / 2,000 ms |
コード長 | 2,161 bytes |
コンパイル時間 | 2,318 ms |
コンパイル使用メモリ | 206,180 KB |
実行使用メモリ | 15,132 KB |
最終ジャッジ日時 | 2023-09-07 16:40:25 |
合計ジャッジ時間 | 6,503 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,384 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 | 59 ms
5,228 KB |
testcase_11 | AC | 106 ms
11,376 KB |
testcase_12 | AC | 117 ms
6,748 KB |
testcase_13 | AC | 35 ms
5,248 KB |
testcase_14 | AC | 135 ms
10,040 KB |
testcase_15 | AC | 186 ms
14,008 KB |
testcase_16 | AC | 166 ms
14,020 KB |
testcase_17 | AC | 177 ms
14,012 KB |
testcase_18 | AC | 190 ms
14,388 KB |
testcase_19 | AC | 203 ms
14,336 KB |
testcase_20 | AC | 135 ms
14,840 KB |
testcase_21 | AC | 135 ms
15,064 KB |
testcase_22 | AC | 135 ms
14,920 KB |
testcase_23 | AC | 135 ms
15,132 KB |
testcase_24 | AC | 136 ms
14,988 KB |
testcase_25 | AC | 137 ms
14,924 KB |
testcase_26 | AC | 136 ms
15,056 KB |
testcase_27 | AC | 136 ms
14,784 KB |
testcase_28 | AC | 138 ms
14,936 KB |
testcase_29 | AC | 137 ms
14,840 KB |
ソースコード
#include<bits/stdc++.h> typedef uint64_t u64; typedef int64_t i64; typedef long double f128; using namespace std; template<typename T> void scan(T& n){ cin>>n; } void scan(){} template<typename T,class... Args> void scan(T& n,Args&... args){ scan(n); scan(args...); } template<typename T> void scanall(T start,T end){ for(;start!=end;++start){ scan(*start); } } template<typename T> void print(T n){ cout<<n; } void print(){} template<typename T,class... Args> void print(T n,Args... args){ print(n); print(args...); } template<typename T> void println(T n){ print(n); cout<<endl; } template<typename T,class... Args> void println(T n,Args... args){ print(n,' '); println(args...); } template<typename T> void printall(T start,T end){ if(start!=end){ print(*start); for(++start;start!=end;++start){ print(' ',*start); } } cout<<endl; } template<typename T> void chmax(T& n,T m){ n=max(n,m); } template<typename T> void chmin(T& n,T m){ n=min(n,m); } template<typename T,typename U> T power(T a,U n){ T res=1; while(n){ res*=(n&1)?a:1; a*=a; n>>=1; } return res; } template<typename T> struct combination{ vector<T> fact; combination(const int Max=3000000):fact(Max+1,1){ for(int i=2;i<=Max;++i){ fact[i]=fact[i-1]*i; } } template<typename U> T nCk(U n,U k){ if(n<k||n<0||k<0){ return 0; } return fact[n]/fact[k]/fact[n-k]; } }; void solve(); int main(){ cout<<fixed<<setprecision(15); bool is_multicase=false; int T=1; if(is_multicase){ scan(T); } for(int i=0;i<T;++i){ solve(); } return 0; } int BFS(int N,vector<vector<int>>& G){ vector<int> cost(N,-1); cost[0]=0; queue<int> que; que.push(0); while(que.size()){ int x=que.front(); que.pop(); for(auto v:G[x]){ if(cost[v]==-1){ cost[v]=cost[x]+1; que.push(v); } } } return cost[N-1]; } void solve(){ int N,M; scan(N,M); vector<vector<int>> G(N); for(int i=0;i<M;++i){ int a,b; scan(a,b); a--,b--; G[a].push_back(b); G[b].push_back(a); } println(BFS(N,G)); }