結果

問題 No.1244 Black Segment
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-09-12 20:31:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 874 bytes
コンパイル時間 5,879 ms
コンパイル使用メモリ 311,220 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2023-09-12 20:31:25
合計ジャッジ時間 10,133 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 49 ms
5,008 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 49 ms
4,852 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 44 ms
7,244 KB
testcase_19 AC 62 ms
8,092 KB
testcase_20 AC 70 ms
8,648 KB
testcase_21 AC 69 ms
8,288 KB
testcase_22 AC 71 ms
8,028 KB
testcase_23 AC 79 ms
8,436 KB
testcase_24 AC 80 ms
8,480 KB
testcase_25 AC 75 ms
8,560 KB
testcase_26 AC 67 ms
8,408 KB
testcase_27 AC 73 ms
8,872 KB
testcase_28 AC 79 ms
8,888 KB
testcase_29 AC 73 ms
8,560 KB
testcase_30 AC 76 ms
8,700 KB
testcase_31 AC 81 ms
8,556 KB
testcase_32 AC 84 ms
8,740 KB
testcase_33 AC 77 ms
8,612 KB
testcase_34 AC 73 ms
8,672 KB
testcase_35 AC 75 ms
9,472 KB
testcase_36 AC 79 ms
9,168 KB
testcase_37 AC 81 ms
9,128 KB
testcase_38 AC 80 ms
8,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<ll,ll>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
  int n,m,a,b;cin>>n>>m>>a>>b;
  vc v(n+1,vc<int>(0));
  rep(i,m){
    int x,y;cin>>x>>y; x--;
    v[x].pb(y); v[y].pb(x);
  }
  vc<int>d(n+1,-1);
  rep(i,a)d[i]=0;
  queue<int>q; 
  rep(i,a)q.push(i);
  while(q.size()){
    int now=q.front(); q.pop();
    for(auto au:v[now])if(d[au]==-1){
      q.push(au);
      d[au]=d[now]+1;
    }
  }
  int ans=1e9;
  for(int i=b;i<=n;i++)if(d[i]!=-1)ans=min(ans,d[i]);
  if(ans==1e9)cout<<-1;
  else cout<<ans;
}
0