結果

問題 No.1244 Black Segment
ユーザー 👑 kmjpkmjp
提出日時 2020-10-02 23:33:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,176 bytes
コンパイル時間 2,052 ms
コンパイル使用メモリ 205,004 KB
実行使用メモリ 9,608 KB
最終ジャッジ日時 2023-09-24 23:50:38
合計ジャッジ時間 5,077 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,064 KB
testcase_01 AC 3 ms
5,768 KB
testcase_02 AC 3 ms
6,008 KB
testcase_03 AC 3 ms
6,060 KB
testcase_04 AC 3 ms
5,864 KB
testcase_05 AC 3 ms
5,948 KB
testcase_06 AC 3 ms
5,760 KB
testcase_07 AC 3 ms
5,912 KB
testcase_08 AC 3 ms
5,820 KB
testcase_09 AC 3 ms
5,780 KB
testcase_10 AC 3 ms
6,064 KB
testcase_11 AC 4 ms
5,788 KB
testcase_12 AC 4 ms
5,868 KB
testcase_13 AC 4 ms
6,064 KB
testcase_14 AC 22 ms
7,296 KB
testcase_15 AC 4 ms
6,060 KB
testcase_16 AC 22 ms
7,296 KB
testcase_17 AC 4 ms
5,856 KB
testcase_18 AC 24 ms
8,296 KB
testcase_19 AC 34 ms
8,796 KB
testcase_20 AC 39 ms
8,764 KB
testcase_21 AC 39 ms
8,848 KB
testcase_22 AC 38 ms
8,948 KB
testcase_23 AC 39 ms
8,952 KB
testcase_24 AC 41 ms
9,048 KB
testcase_25 AC 40 ms
9,072 KB
testcase_26 AC 38 ms
9,112 KB
testcase_27 AC 44 ms
9,388 KB
testcase_28 AC 42 ms
9,204 KB
testcase_29 AC 43 ms
8,932 KB
testcase_30 AC 42 ms
9,352 KB
testcase_31 AC 48 ms
9,168 KB
testcase_32 AC 54 ms
9,396 KB
testcase_33 AC 42 ms
9,208 KB
testcase_34 AC 40 ms
9,144 KB
testcase_35 AC 42 ms
9,396 KB
testcase_36 AC 42 ms
9,552 KB
testcase_37 AC 42 ms
9,608 KB
testcase_38 AC 42 ms
9,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M,A,B;
vector<int> E[101010];
int D[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>A>>B;
	FOR(i,N+1) D[i]=1<<20;
	A--;
	FOR(i,M) {
		cin>>x>>y;
		E[x-1].push_back(y);
		E[y].push_back(x-1);
	}
	
	queue<int> Q;
	for(i=0;i<=A;i++) {
		D[i]=0;
		Q.push(i);
	}
	while(Q.size()) {
		x=Q.front();
		Q.pop();
		if(x>=B) return _P("%d\n",D[x]);
		FORR(e,E[x]) if(D[e]>D[x]+1) {
			D[e]=D[x]+1;
			Q.push(e);
		}
	}
	cout<<-1<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0