結果
| 問題 |
No.1244 Black Segment
|
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2020-10-02 22:15:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 46 ms / 2,000 ms |
| コード長 | 1,280 bytes |
| コンパイル時間 | 1,736 ms |
| コンパイル使用メモリ | 173,116 KB |
| 実行使用メモリ | 9,600 KB |
| 最終ジャッジ日時 | 2024-07-17 21:31:52 |
| 合計ジャッジ時間 | 4,121 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=100005,INF=1<<30;
vector<int> G[MAX];
int dis[MAX];
int A,B;
void BFS(){
for(int i=0;i<MAX;i++) dis[i]=INF;
queue<int> Q;
for(int i=0;i<=A;i++){
dis[i]=0;
Q.push(i);
}
while(!Q.empty()){
int u=Q.front();Q.pop();
for(int to:G[u]){
if(chmin(dis[to],dis[u]+1)){
Q.push(to);
}
}
}
}
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int N,M;cin>>N>>M>>A>>B;
A--;B--;
for(int i=0;i<M;i++){
int a,b;cin>>a>>b;
a--;b--;
G[a].push_back(b+1);
G[b+1].push_back(a);
}
BFS();
int ans=INF;
for(int i=B+1;i<MAX;i++) chmin(ans,dis[i]);
if(ans==INF) cout<<-1<<endl;
else cout<<ans<<endl;
}
Rubikun