結果
| 問題 |
No.1244 Black Segment
|
| コンテスト | |
| ユーザー |
tute7627
|
| 提出日時 | 2020-02-11 13:03:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 85 ms / 2,000 ms |
| コード長 | 1,554 bytes |
| コンパイル時間 | 1,841 ms |
| コンパイル使用メモリ | 178,492 KB |
| 実行使用メモリ | 12,584 KB |
| 最終ジャッジ日時 | 2024-10-08 11:13:06 |
| 合計ジャッジ時間 | 5,246 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
#define rep(i,n,m) for(int i = (n); i < (int)(m); i++)
#define rrep(i,n,m) for(int i = (m) - 1; i >= (int)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e9+1;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
template<typename T>
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
vector<ll>dist(200001);
using P=pair<ll,ll>;
void bfs(ll k,vector<vector<ll>>&g){
queue<P> q;
ll n=g.size();
q.emplace(k,0);
fill(dist.begin(),dist.begin()+n,INF);
while(!q.empty()){
ll x=q.front().first;
ll len=q.front().second;
if(dist[x]==INF){
dist[x]=len;
for(ll i=0;i<g[x].size();i++){
q.emplace(g[x][i],len+1);
}
}
q.pop();
}
}
int main(){
int n,m,a,b;cin>>n>>m>>a>>b;
a--;b--;
vector<vector<ll>>g(n+1);
rep(i,0,m){
int l,r;
cin>>l>>r;
l--;
chmax(l,a);
chmax(r,a);
chmin(l,b+1);
chmin(r,b+1);
g[l].push_back(r);
g[r].push_back(l);
}
bfs(a,g);
if(dist[b+1]!=INF)cout<<dist[b+1]<<endl;
else cout<<-1<<endl;
return 0;
}
tute7627