結果
問題 |
No.1244 Black Segment
|
ユーザー |
![]() |
提出日時 | 2023-09-12 20:31:12 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 92 ms / 2,000 ms |
コード長 | 874 bytes |
コンパイル時間 | 5,523 ms |
コンパイル使用メモリ | 313,548 KB |
実行使用メモリ | 9,472 KB |
最終ジャッジ日時 | 2024-06-30 08:07:48 |
合計ジャッジ時間 | 9,678 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#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; }