結果

問題 No.2674 k-Walk on Bipartite
ユーザー GGanariGGanari
提出日時 2024-03-15 22:59:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,904 bytes
コンパイル時間 3,398 ms
コンパイル使用メモリ 228,972 KB
実行使用メモリ 14,160 KB
最終ジャッジ日時 2024-03-15 22:59:37
合計ジャッジ時間 6,074 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,272 KB
testcase_01 AC 4 ms
8,272 KB
testcase_02 AC 4 ms
8,272 KB
testcase_03 AC 5 ms
8,272 KB
testcase_04 AC 5 ms
8,272 KB
testcase_05 AC 4 ms
8,272 KB
testcase_06 AC 4 ms
8,272 KB
testcase_07 AC 56 ms
12,624 KB
testcase_08 AC 78 ms
12,240 KB
testcase_09 AC 48 ms
12,496 KB
testcase_10 AC 94 ms
13,136 KB
testcase_11 AC 57 ms
11,984 KB
testcase_12 AC 94 ms
12,752 KB
testcase_13 AC 46 ms
11,984 KB
testcase_14 AC 14 ms
9,680 KB
testcase_15 AC 103 ms
13,648 KB
testcase_16 AC 69 ms
13,008 KB
testcase_17 AC 67 ms
12,112 KB
testcase_18 AC 25 ms
10,704 KB
testcase_19 AC 58 ms
12,496 KB
testcase_20 AC 50 ms
12,368 KB
testcase_21 AC 76 ms
12,496 KB
testcase_22 AC 108 ms
14,160 KB
testcase_23 AC 4 ms
8,272 KB
testcase_24 AC 4 ms
8,272 KB
testcase_25 AC 4 ms
8,272 KB
testcase_26 AC 5 ms
8,272 KB
testcase_27 AC 5 ms
8,272 KB
testcase_28 AC 4 ms
8,272 KB
testcase_29 AC 4 ms
8,272 KB
testcase_30 AC 4 ms
8,272 KB
testcase_31 AC 4 ms
8,272 KB
testcase_32 AC 4 ms
8,272 KB
testcase_33 AC 4 ms
8,272 KB
testcase_34 AC 4 ms
8,272 KB
testcase_35 AC 5 ms
8,272 KB
testcase_36 AC 5 ms
8,272 KB
testcase_37 AC 4 ms
8,272 KB
testcase_38 AC 4 ms
8,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
#define INF 1000000001LL
#define LNF 1000000000000000001LL
#define MOD 1000000007LL
#define MAX 200001
#define long long long
#define all(x) x.begin(),x.end()
using namespace std;

vector<int> graph[MAX];
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);

    int n,m;
    cin >> n >> m;
    int s,e,k;
    cin >> s >> e >> k;

    for(int i = 0; i<m; i++)
    {
        int a,b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    
    vector<int> vis(n+1,-1);
    queue<int> q;
    q.push(s);
    while(!q.empty())
    {
        int x = q.front();
        q.pop();

        for(int y : graph[x])
        {
            if(vis[y] == -1)
            {
                if(vis[x] == -1)
                    vis[y] = 1;
                else
                    vis[y] = vis[x]+1;
                q.push(y);
            }
        }
    }

    if(n == 1)
    {
        cout << "No\n";
        return 0;
    }

    if(vis[e] <= k)
    {
        if(vis[e] == -1)
        {
            if(s == e)
            {
                if(k%2 == 0)
                {
                    cout << "Unknown\n";
                }
                else
                    cout << "No\n";
                return 0;
            }
            if(n == 2 && k%2)
            {
                cout << "Unknown\n";
            }
            else if(n == 2)
            {
                cout << "No\n";
            }
            else
                cout << "Unknown\n";
        } 
        else if(vis[e]%2 == k%2)
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    else
    {
        if(vis[e]%2 == k%2)
            cout << "Unknown\n";
        else
            cout << "No\n";
    }
    return 0;
}
0