結果

問題 No.2674 k-Walk on Bipartite
ユーザー tour2sttour2st
提出日時 2024-03-15 23:38:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 1,550 bytes
コンパイル時間 932 ms
コンパイル使用メモリ 98,680 KB
実行使用メモリ 16,448 KB
最終ジャッジ日時 2024-03-15 23:38:47
合計ジャッジ時間 4,495 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,640 KB
testcase_01 AC 4 ms
8,640 KB
testcase_02 AC 4 ms
8,640 KB
testcase_03 AC 4 ms
8,640 KB
testcase_04 AC 3 ms
8,640 KB
testcase_05 AC 4 ms
8,640 KB
testcase_06 AC 4 ms
8,640 KB
testcase_07 AC 104 ms
13,120 KB
testcase_08 AC 144 ms
14,784 KB
testcase_09 AC 89 ms
12,224 KB
testcase_10 AC 186 ms
15,936 KB
testcase_11 AC 110 ms
13,248 KB
testcase_12 AC 184 ms
15,808 KB
testcase_13 AC 90 ms
11,968 KB
testcase_14 AC 21 ms
9,664 KB
testcase_15 AC 198 ms
16,448 KB
testcase_16 AC 131 ms
13,888 KB
testcase_17 AC 142 ms
14,400 KB
testcase_18 AC 53 ms
10,816 KB
testcase_19 AC 109 ms
12,480 KB
testcase_20 AC 92 ms
12,736 KB
testcase_21 AC 153 ms
14,784 KB
testcase_22 AC 213 ms
16,448 KB
testcase_23 AC 4 ms
8,640 KB
testcase_24 AC 4 ms
8,640 KB
testcase_25 AC 4 ms
8,640 KB
testcase_26 AC 4 ms
8,640 KB
testcase_27 AC 5 ms
8,640 KB
testcase_28 AC 4 ms
8,640 KB
testcase_29 AC 4 ms
8,640 KB
testcase_30 AC 4 ms
8,640 KB
testcase_31 AC 4 ms
8,640 KB
testcase_32 AC 4 ms
8,640 KB
testcase_33 AC 4 ms
8,640 KB
testcase_34 AC 4 ms
8,640 KB
testcase_35 AC 4 ms
8,640 KB
testcase_36 AC 4 ms
8,640 KB
testcase_37 AC 4 ms
8,640 KB
testcase_38 AC 4 ms
8,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <random>
#include <time.h>
#include <map>
using namespace std;

int n,m,s,t,k,a,b;
vector<int>e[200000];
int length[200000];
bool visited[200000];

void dfs(int now, int len=0)
{
    if(visited[now]) return;
    visited[now]=true;
    length[now]=len;
    for(int nxt:e[now]) dfs(nxt, len+1);
}

int main()
{
    cin >> n >> m >> s >> t >> k;
    s--;t--;
    for(int i=0;i<m;i++)
    {
        cin >> a >> b;
        a--;b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    //同じであるとき
    if(s==t)
    {
        //1点のみならパスが存在しない
        if(n==1) cout << "No" << endl;
        //偶数回移動して戻ってこれる
        else if(k%2==0)
        {
            if(e[s].size()) cout << "Yes" << endl;
            else cout << "Unknown" << endl;
        }
        //これない
        else
        {
            cout << "No" << endl;
        }
        return 0;
    }
    dfs(s);
    if(visited[t])
    {
        if(length[t]%2!=k%2)
        {
            cout << "No" << endl;
        }
        else
        {
            if(length[t]<=k)
            {
                cout << "Yes" << endl;
            }
            else
            {
                cout << "Unknown" << endl;
            }
        }
    }
    else
    {
        //Noの時もある
        if(n==2 && k%2==0) cout << "No" << endl;
        else cout << "Unknown" << endl;
        
    }
}
0