結果

問題 No.1244 Black Segment
ユーザー tempura_pptempura_pp
提出日時 2020-08-08 21:34:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,219 bytes
コンパイル時間 1,355 ms
コンパイル使用メモリ 122,280 KB
最終ジャッジ日時 2025-01-12 18:55:49
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n,m,a,b;
cin>>n>>m>>a>>b;
vector<vector<int>> v(n+1);
rep(i,m){
int x,y;
cin>>x>>y;
assert(x<=y);
--x;
v[x].push_back(y);
v[y].push_back(x);
}
vector<int> dist(n+1,inf);
queue<int> q;
rep(i,a){
dist[i] = 0;
q.push(i);
}
while(q.size()){
int x=q.front();q.pop();
for(auto to : v[x]){
if(dist[to]==inf){
dist[to]=dist[x]+1;
q.push(to);
}
}
}
int ans=inf;
REP(i,b,n+1)ans=min(ans,dist[i]);
if(ans==inf)cout<<-1<<endl;
else cout<<ans<<endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0