結果

問題 No.3291 K-step Navigation
ユーザー snrnsidy
提出日時 2025-10-03 22:35:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,506 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 100,612 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-03 22:35:48
合計ジャッジ時間 3,617 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <cstring>
#include <queue>
#include <bitset>
#include <map>
#include <stack>

using namespace std;

long long int n,m,k,s,t,u,v;
bool e[2001][2001];
int dp[2001][2][2];

int main() 
{
	cin.tie(0);
    ios::sync_with_stdio(false);

	cin >> n >> m >> k >> s >> t;
	for(int i=0;i<m;i++)
	{
		cin >> u >> v;
		e[u][v] = true;
		e[v][u] = true;
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<2;j++)
		{
			for(int k=0;k<2;k++)
			{
				dp[i][j][k] = -1;
			}
		}
	}

	dp[s][0][0] = 0;
	queue <pair<int,pair<int,int>>> que;
	que.push(make_pair(s,make_pair(0,0)));

	while(!que.empty())
	{
		int now = que.front().first;
		int p = que.front().second.first;
		int f = que.front().second.second;
		que.pop();

		for(int next=1;next<=n;next++)
		{
			if(next==now) continue;
			if(e[now][next])
			{
				if(dp[next][(1-p)][f]==-1)
				{
					dp[next][(1-p)][f] = dp[now][p][f] + 1;
					que.push(make_pair(next,make_pair(1-p,f)));
				}
			}
			else
			{
				if(f==0)
				{
					if(dp[next][(1-p)][1-f]==-1)
					{
						dp[next][(1-p)][1-f] = dp[now][p][f] + 1;
						que.push(make_pair(next,make_pair(1-p,1-f)));
					}					
				}
			}
		}
	}	
	long long int res = 2e18;
	if(dp[t][k%2][0]!=-1) res = min(res,(long long int)dp[t][k%2][0]);
	if(dp[t][k%2][1]!=-1) res = min(res,(long long int)dp[t][k%2][1]);

	if(res <= k) cout << "Yes" << '\n';
	else cout << "No" << '\n';

    return 0;
}
0