結果

問題 No.1244 Black Segment
ユーザー tko919tko919
提出日時 2021-08-30 17:19:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,019 bytes
コンパイル時間 2,184 ms
コンパイル使用メモリ 206,808 KB
実行使用メモリ 9,096 KB
最終ジャッジ日時 2023-08-15 16:50:00
合計ジャッジ時間 7,392 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 43 ms
4,764 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 41 ms
5,088 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 37 ms
7,272 KB
testcase_19 AC 55 ms
7,732 KB
testcase_20 AC 58 ms
8,552 KB
testcase_21 AC 59 ms
8,296 KB
testcase_22 AC 61 ms
8,064 KB
testcase_23 AC 67 ms
8,312 KB
testcase_24 AC 65 ms
8,308 KB
testcase_25 AC 61 ms
8,592 KB
testcase_26 AC 58 ms
8,252 KB
testcase_27 AC 64 ms
8,920 KB
testcase_28 AC 65 ms
8,580 KB
testcase_29 AC 64 ms
8,632 KB
testcase_30 AC 62 ms
8,648 KB
testcase_31 AC 67 ms
8,560 KB
testcase_32 AC 67 ms
8,524 KB
testcase_33 AC 67 ms
8,652 KB
testcase_34 AC 62 ms
8,548 KB
testcase_35 AC 62 ms
9,044 KB
testcase_36 AC 62 ms
9,092 KB
testcase_37 AC 63 ms
9,096 KB
testcase_38 AC 65 ms
8,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}



int main(){
   int n,m,a,b;
   cin>>n>>m>>a>>b;
   a--;
   vector g(n+1,vector<int>());
   vector<int> dist(n+1,inf);
   queue<int> que;
   rep(i,0,a+1){
      dist[i]=0;
      que.push(i);
   }
   rep(_,0,m){
      int x,y;
      cin>>x>>y;
      x--;
      g[x].push_back(y);
      g[y].push_back(x);
   }

   while(!que.empty()){
      int v=que.front();
      que.pop();
      if(b<=v){
         cout<<dist[v]<<'\n';
         return 0;
      }
      for(auto& to:g[v])if(chmin(dist[to],dist[v]+1)){
         que.push(to);
      }
   }
   puts("-1");
   return 0;
}
0