結果

問題 No.2674 k-Walk on Bipartite
ユーザー ゆにぽけゆにぽけ
提出日時 2024-03-15 22:10:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,493 bytes
コンパイル時間 1,547 ms
コンパイル使用メモリ 140,484 KB
実行使用メモリ 15,008 KB
最終ジャッジ日時 2024-03-15 22:10:36
合計ジャッジ時間 4,425 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 75 ms
13,476 KB
testcase_08 AC 105 ms
12,800 KB
testcase_09 AC 59 ms
12,744 KB
testcase_10 AC 168 ms
14,720 KB
testcase_11 AC 62 ms
10,624 KB
testcase_12 AC 129 ms
13,312 KB
testcase_13 AC 56 ms
11,564 KB
testcase_14 AC 17 ms
9,984 KB
testcase_15 AC 136 ms
15,004 KB
testcase_16 AC 99 ms
15,008 KB
testcase_17 AC 89 ms
11,776 KB
testcase_18 AC 31 ms
9,088 KB
testcase_19 AC 69 ms
12,132 KB
testcase_20 AC 63 ms
13,780 KB
testcase_21 AC 104 ms
12,672 KB
testcase_22 AC 132 ms
14,456 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 2 ms
6,548 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
6,548 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 2 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
testcase_34 AC 2 ms
6,548 KB
testcase_35 AC 2 ms
6,548 KB
testcase_36 AC 2 ms
6,548 KB
testcase_37 AC 2 ms
6,548 KB
testcase_38 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;

#include<algorithm>
#include<vector>
#include<cassert>
using namespace std;
struct UnionFind
{
	private:
	int n;
	vector<int> par,siz;

	public:
	UnionFind(int n) :n(n),par(n,-1),siz(n,1) {}

	int root(int u) 
	{
		assert(0 <= u && u < n);
		return (par[u] < 0 ? u:par[u] = root(par[u]));
	}

	bool same(int u,int v)
	{
		assert(0 <= u && u < n && 0 <= v && v < n);
		return root(u) == root(v);
	}

	bool unite(int u,int v)
	{
		assert(0 <= u && u < n && 0 <= v && v < n);
		u = root(u),v = root(v);
		if(u == v) return false;

		if(siz[u] < siz[v]) swap(u,v);

		siz[u] += siz[v];
		par[v] = u;

		return true;
	}

	int size(int u)
	{
		assert(0 <= u && u < n);
		return siz[root(u)];
	}

	vector<vector<int>> components()
	{
		vector<vector<int>> ret(n);
		for(int u = 0;u < n;u++) ret[root(u)].push_back(u);

		ret.erase(remove_if(ret.begin(),ret.end(),[](vector<int> v) { return v.empty();}),ret.end());

		return ret;
	}
};

void Main()
{
	int N,M;
	cin >> N >> M;
	int s,t,k;
	cin >> s >> t >> k;
	s--; t--;
	vector<vector<int>> G(N);
	UnionFind uf(N);
	for(int i = 0;i < M;i++)
	{
		int u,v;
		cin >> u >> v;
		u--; v--;
		G[u].push_back(v);
		G[v].push_back(u);
		uf.unite(u,v);
	}
	if(uf.same(s,t))
	{
		vector<int> C(N,-1);
		auto dfs = [&](auto dfs,int u,int c) -> void
		{
			C[u] = c;
			for(int v : G[u])
			{
				if(C[v] == -1)
				{
					dfs(dfs,v,1 - c);
				}
			}
		};
		dfs(dfs,s,0);
		if(C[s] == C[t] && k % 2 == 1)
		{
			cout << "No\n";
			return;
		}
		if(C[s] != C[t] && k % 2 == 0)
		{
			cout << "No\n";
			return; 
		}
		vector<int> dp(N,-1);
		dp[s] = 0;
		queue<int> Q;
		Q.push(s);
		while(!Q.empty())
		{
			int u = Q.front();
			Q.pop();
			for(int v : G[u])
			{
				if(dp[v] == -1)
				{
					dp[v] = dp[u] + 1;
					Q.push(v);
				}
			}
		}
		if(dp[t] <= k)
		{
			cout << "Yes\n";
		}
		else
		{
			cout << "Unknown\n";
		}
	}
	else
	{
		cout << "Unknown\n";
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	/* cin >> tt; */
	while(tt--) Main();
}

0