結果

問題 No.2674 k-Walk on Bipartite
ユーザー nononnonon
提出日時 2024-03-15 23:08:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 1,511 bytes
コンパイル時間 2,248 ms
コンパイル使用メモリ 212,636 KB
実行使用メモリ 16,344 KB
最終ジャッジ日時 2024-03-15 23:08:53
合計ジャッジ時間 5,196 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,328 KB
testcase_01 AC 4 ms
10,328 KB
testcase_02 AC 4 ms
10,328 KB
testcase_03 AC 5 ms
10,328 KB
testcase_04 AC 4 ms
10,328 KB
testcase_05 AC 4 ms
10,328 KB
testcase_06 AC 4 ms
10,328 KB
testcase_07 AC 60 ms
14,680 KB
testcase_08 AC 74 ms
14,296 KB
testcase_09 AC 51 ms
14,552 KB
testcase_10 AC 99 ms
15,192 KB
testcase_11 AC 60 ms
14,040 KB
testcase_12 AC 98 ms
14,808 KB
testcase_13 AC 52 ms
14,040 KB
testcase_14 AC 15 ms
11,736 KB
testcase_15 AC 114 ms
15,704 KB
testcase_16 AC 80 ms
15,192 KB
testcase_17 AC 72 ms
14,168 KB
testcase_18 AC 30 ms
12,760 KB
testcase_19 AC 67 ms
14,552 KB
testcase_20 AC 57 ms
14,424 KB
testcase_21 AC 85 ms
14,552 KB
testcase_22 AC 126 ms
16,344 KB
testcase_23 AC 4 ms
10,328 KB
testcase_24 AC 4 ms
10,328 KB
testcase_25 AC 4 ms
10,328 KB
testcase_26 AC 5 ms
10,328 KB
testcase_27 AC 5 ms
10,328 KB
testcase_28 AC 5 ms
10,328 KB
testcase_29 AC 5 ms
10,328 KB
testcase_30 AC 4 ms
10,328 KB
testcase_31 AC 4 ms
10,328 KB
testcase_32 AC 5 ms
10,328 KB
testcase_33 AC 4 ms
10,328 KB
testcase_34 AC 5 ms
10,328 KB
testcase_35 AC 4 ms
10,328 KB
testcase_36 AC 4 ms
10,328 KB
testcase_37 AC 5 ms
10,328 KB
testcase_38 AC 4 ms
10,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/dsu>
using namespace std;
int N,M,s,t,K,dist[2<<17];
vector<int>G[2<<17];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>N>>M>>s>>t>>K;
    s--,t--;
    if(N==1)
    {
        cout<<"No\n";
        return 0;
    }
    if(N==2)
    {
        if(M==0)
        {
            if(K&1)
            {
                cout<<(s!=t?"Unknown\n":"No\n");
            }
            else
            {
                cout<<(s==t?"Unknown\n":"No\n");
            }
        }
        else
        {
            if(K&1)
            {
                cout<<(s!=t?"Yes\n":"No\n");
            }
            else
            {
                cout<<(s==t?"Yes\n":"No\n");
            }
        }
        return 0;
    }
    atcoder::dsu uf(N);
    for(;M--;)
    {
        int u,v;
        cin>>u>>v;
        u--,v--;
        G[u].push_back(v);
        G[v].push_back(u);
        uf.merge(u,v);
    }
    for(int i=0;i<N;i++)dist[i]=1<<30;
    dist[s]=0;
    queue<int>q;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int v:G[u])if(dist[v]>dist[u]+1)
        {
            dist[v]=dist[u]+1;
            q.push(v);
        }
    }
    if(dist[t]<=K&&(K-dist[t])%2==0)
    {
        cout<<"Yes\n";
        return 0;
    }
    if(uf.same(s,t))
    {
        assert(dist[t]<(1<<30));
        if((dist[t]-K)%2!=0)
        {
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Unknown\n";
}
0