結果

問題 No.1244 Black Segment
ユーザー 👑 tute7627tute7627
提出日時 2020-02-11 13:03:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 1,554 bytes
コンパイル時間 1,990 ms
コンパイル使用メモリ 172,960 KB
実行使用メモリ 12,452 KB
最終ジャッジ日時 2024-04-17 02:08:13
合計ジャッジ時間 5,654 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 3 ms
5,248 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 60 ms
9,316 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 57 ms
8,836 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 50 ms
9,408 KB
testcase_19 AC 77 ms
10,288 KB
testcase_20 AC 79 ms
10,176 KB
testcase_21 AC 79 ms
10,236 KB
testcase_22 AC 81 ms
10,300 KB
testcase_23 AC 91 ms
11,072 KB
testcase_24 AC 89 ms
10,416 KB
testcase_25 AC 81 ms
10,364 KB
testcase_26 AC 89 ms
10,608 KB
testcase_27 AC 93 ms
10,368 KB
testcase_28 AC 91 ms
11,032 KB
testcase_29 AC 94 ms
10,496 KB
testcase_30 AC 85 ms
10,920 KB
testcase_31 AC 99 ms
10,368 KB
testcase_32 AC 99 ms
10,368 KB
testcase_33 AC 96 ms
10,112 KB
testcase_34 AC 69 ms
11,992 KB
testcase_35 AC 68 ms
10,388 KB
testcase_36 AC 77 ms
10,424 KB
testcase_37 AC 91 ms
12,452 KB
testcase_38 AC 87 ms
11,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0