結果
| 問題 |
No.3291 K-step Navigation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-03 23:05:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,605 bytes |
| コンパイル時間 | 1,017 ms |
| コンパイル使用メモリ | 102,624 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-10-03 23:05:32 |
| 合計ジャッジ時間 | 3,064 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 WA * 8 |
ソースコード
#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];
long long 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;
}
memset(dp,-1,sizeof(dp));
dp[s][0][0] = 0;
dp[t][1][0] = 0;
queue <pair<int,pair<int,int>>> que;
que.push(make_pair(s,make_pair(0,0)));
que.push(make_pair(t,make_pair(1,0)));
while(!que.empty())
{
int now = que.front().first;
int state = que.front().second.first;
int p = que.front().second.second;
que.pop();
for(int next=1;next<=n;next++)
{
if(now==next) continue;
if(e[now][next])
{
if(dp[next][state][1-p]==-1)
{
dp[next][state][1-p] = dp[now][state][p] + 1;
que.push(make_pair(next,make_pair(state,1-p)));
}
}
}
}
if(dp[t][0][k%2]!=-1)
{
if(dp[t][0][k%2] <= k)
{
cout << "Yes" << '\n';
return 0;
}
}
for(int a=1;a<=n;a++)
{
for(int b=1;b<=n;b++)
{
if(a==b) continue;
if(!e[a][b])
{
for(int i=0;i<2;i++)
{
if(dp[a][0][i]==-1) continue;
for(int j=0;j<2;j++)
{
if(dp[b][1][j]==-1) continue;
long long int D = dp[a][0][i] + dp[b][1][j] + 1;
if((k-D)%2==0 && D<=k)
{
cout << "Yes" << '\n';
return 0;
}
}
}
}
}
}
cout << "No" << '\n';
return 0;
}