結果
| 問題 |
No.3291 K-step Navigation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-03 22:44:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,636 bytes |
| コンパイル時間 | 1,220 ms |
| コンパイル使用メモリ | 102,744 KB |
| 実行使用メモリ | 28,376 KB |
| 最終ジャッジ日時 | 2025-10-03 22:45:22 |
| 合計ジャッジ時間 | 23,425 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 16 WA * 4 TLE * 1 -- * 29 |
ソースコード
#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];
bool dp[2001][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;
}
dp[s][0][0][0] = true;
queue <pair<pair<int,int>,pair<int,int>>> que;
que.push(make_pair(make_pair(s,0),make_pair(0,0)));
while(!que.empty())
{
int now = que.front().first.first;
int d = que.front().first.second;
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(d+1 <= n && dp[next][d+1][(1-p)][f]==false)
{
dp[next][d+1][(1-p)][f] = true;
que.push(make_pair(make_pair(next,d+1),make_pair(1-p,f)));
}
}
else
{
if(f==0)
{
if(d+1 <= n && dp[next][d+1][(1-p)][1-f]==false)
{
dp[next][d+1][(1-p)][1-f] = dp[now][d+1][p][f] + 1;
que.push(make_pair(make_pair(next,d+1),make_pair(1-p,1-f)));
}
}
}
}
}
long long int res = 2e18;
for(int i=0;i<=n;i++)
{
bool ok = false;
for(int j=0;j<2;j++)
{
for(int k=0;k<2;k++)
{
if(dp[t][i][j][k])
{
ok = true;
}
}
}
if(ok)
{
long long int d = k - i;
if(d%2==0)
{
cout << "Yes" << '\n';
return 0;
}
}
}
cout << "No" << '\n';
return 0;
}