結果

問題 No.2674 k-Walk on Bipartite
ユーザー kotatsugamekotatsugame
提出日時 2024-03-15 21:43:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,054 bytes
コンパイル時間 759 ms
コンパイル使用メモリ 77,616 KB
実行使用メモリ 15,452 KB
最終ジャッジ日時 2024-03-15 21:43:18
合計ジャッジ時間 3,533 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
9,692 KB
testcase_01 AC 5 ms
9,692 KB
testcase_02 AC 5 ms
9,692 KB
testcase_03 AC 5 ms
9,564 KB
testcase_04 AC 5 ms
9,564 KB
testcase_05 AC 5 ms
9,564 KB
testcase_06 AC 4 ms
9,564 KB
testcase_07 AC 60 ms
13,916 KB
testcase_08 AC 88 ms
13,532 KB
testcase_09 AC 54 ms
13,788 KB
testcase_10 AC 100 ms
14,428 KB
testcase_11 AC 59 ms
13,276 KB
testcase_12 AC 101 ms
13,916 KB
testcase_13 AC 52 ms
13,276 KB
testcase_14 AC 15 ms
10,972 KB
testcase_15 AC 118 ms
14,812 KB
testcase_16 AC 78 ms
14,300 KB
testcase_17 AC 79 ms
13,276 KB
testcase_18 AC 31 ms
11,996 KB
testcase_19 AC 68 ms
13,788 KB
testcase_20 AC 56 ms
13,660 KB
testcase_21 AC 84 ms
13,788 KB
testcase_22 AC 130 ms
15,452 KB
testcase_23 AC 5 ms
9,564 KB
testcase_24 AC 5 ms
9,564 KB
testcase_25 AC 5 ms
9,564 KB
testcase_26 AC 5 ms
9,564 KB
testcase_27 AC 6 ms
9,692 KB
testcase_28 AC 5 ms
9,692 KB
testcase_29 AC 5 ms
9,692 KB
testcase_30 AC 5 ms
9,692 KB
testcase_31 AC 5 ms
9,564 KB
testcase_32 AC 5 ms
9,564 KB
testcase_33 AC 5 ms
9,564 KB
testcase_34 AC 5 ms
9,564 KB
testcase_35 AC 5 ms
9,692 KB
testcase_36 AC 5 ms
9,692 KB
testcase_37 AC 5 ms
9,692 KB
testcase_38 AC 5 ms
9,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
#include<cassert>
using namespace std;
int N,M;
vector<int>G[2<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int s,t,k;
	cin>>N>>M>>s>>t>>k;
	s--,t--;
	for(int i=0;i<M;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	if(s==t)
	{
		if(N==1||k%2==1)cout<<"No\n";
		else
		{
			if(!G[s].empty())cout<<"Yes\n";
			else cout<<"Unknown\n";
		}
		return 0;
	}
	queue<int>Q;
	Q.push(s);
	vector<int>dist(N,(int)1e9);
	dist[s]=0;
	while(!Q.empty())
	{
		int u=Q.front();Q.pop();
		for(int v:G[u])
		{
			if(dist[v]>dist[u]+1)
			{
				dist[v]=dist[u]+1;
				Q.push(v);
			}
		}
	}
	if(dist[t]==(int)1e9)
	{
		if(k%2==1)cout<<"Unknown\n";
		else
		{
			if(N>=3)cout<<"Unknown\n";
			else cout<<"No\n";
		}
	}
	else if(dist[t]%2==1)
	{
		if(k%2==0)cout<<"No\n";
		else
		{
			if(dist[t]<=k)cout<<"Yes\n";
			else cout<<"Unknown\n";
		}
	}
	else
	{
		if(k%2==1)cout<<"No\n";
		else
		{
			if(dist[t]<=k)cout<<"Yes\n";
			else cout<<"Unknown\n";
		}
	}
}
0