結果
問題 | No.1244 Black Segment |
ユーザー |
![]() |
提出日時 | 2021-08-30 17:19:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 111 ms / 2,000 ms |
コード長 | 1,019 bytes |
コンパイル時間 | 2,158 ms |
コンパイル使用メモリ | 201,124 KB |
最終ジャッジ日時 | 2025-01-24 04:05:31 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#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;}