結果

問題 No.2674 k-Walk on Bipartite
ユーザー 👑 binapbinap
提出日時 2024-03-15 21:55:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,397 bytes
コンパイル時間 4,643 ms
コンパイル使用メモリ 280,228 KB
実行使用メモリ 19,436 KB
最終ジャッジ日時 2024-09-30 01:02:46
合計ジャッジ時間 8,455 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,820 KB
testcase_03 AC 2 ms
6,816 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,820 KB
testcase_07 AC 120 ms
15,204 KB
testcase_08 AC 193 ms
16,612 KB
testcase_09 AC 97 ms
14,892 KB
testcase_10 AC 226 ms
17,952 KB
testcase_11 AC 133 ms
13,208 KB
testcase_12 AC 236 ms
17,304 KB
testcase_13 AC 88 ms
14,112 KB
testcase_14 AC 22 ms
9,176 KB
testcase_15 AC 255 ms
19,188 KB
testcase_16 AC 160 ms
16,136 KB
testcase_17 AC 174 ms
15,796 KB
testcase_18 AC 53 ms
10,376 KB
testcase_19 AC 109 ms
14,872 KB
testcase_20 AC 94 ms
14,592 KB
testcase_21 AC 187 ms
17,936 KB
testcase_22 AC 254 ms
19,436 KB
testcase_23 AC 2 ms
6,820 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
6,816 KB
testcase_27 AC 2 ms
6,820 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
6,816 KB
testcase_31 AC 2 ms
6,816 KB
testcase_32 AC 2 ms
6,820 KB
testcase_33 AC 2 ms
6,820 KB
testcase_34 AC 2 ms
6,816 KB
testcase_35 AC 2 ms
6,816 KB
testcase_36 AC 2 ms
6,816 KB
testcase_37 AC 2 ms
6,820 KB
testcase_38 AC 2 ms
6,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef long double ld;
typedef pair<int, int> P;

ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}

template<typename T> void chmin(T& a, T b){a = min(a, b);}
template<typename T> void chmax(T& a, T b){a = max(a, b);}

template<typename T>
struct Edge_Dijkstra{
	int from, to;
	T cost;
	Edge_Dijkstra(int from, int to, T cost) : from(from), to(to), cost(cost) {};
};

const long long INF = 1001001001;
template<typename T>
struct Dijkstra{
	int n, m;
	vector<bool> initialized;
	vector<Edge_Dijkstra<T>> E;
	vector<vector<int>> G;
	map<int, vector<T>> dist;
	map<int, vector<int>> idx;
	Dijkstra(int _n) : n(_n), m(0), initialized(n, false), G(n){}
	void add_edge(int from, int to, T cost){
		Edge_Dijkstra e(from, to, cost);
		E.push_back(e);
		G[from].emplace_back(m);
		m++;
	}
	void calc(int s){
		initialized[s] = true;
		dist[s] = vector<T>(n, INF);
		idx[s] = vector<int>(n, -1);
		priority_queue<tuple<T, int, int>, vector<tuple<T, int, int>>, greater<tuple<T, int, int>>> pq;
		pq.emplace(0, s, -1);
		while(pq.size()){
			auto [cost, from, index] = pq.top(); pq.pop();
			if(dist[s][from] <= cost) continue;
			dist[s][from] = cost;
			idx[s][from] = index;
			for(int index : G[from]){
				int to = E[index].to;
				T cost_plus = E[index].cost;
				if(dist[s][to] <= cost + cost_plus) continue;
				pq.emplace(cost + cost_plus, to, index);
			}
		}
	}
	int farthest(int s){
		if(!initialized[s]) calc(s);
		int idx = 0;
		rep(i, n) if(dist[s][i] > dist[s][idx]) idx = i;
		return idx;
	}
	T get_dist(int s, int t){
		if(!initialized[s]) calc(s);
		return dist[s][t];
	}
	vi restore(int s, int t){
		if(!initialized[s]) calc(s);
		if(dist[s][t] == INF) return vi(0);
		vi res;
		while(idx[s][t] != -1){
			auto e = E[idx[s][t]];
			res.push_back(idx[s][t]);
			t = e.from;
		}
	reverse(res.begin(), res.end());
	return res;
	}
};

int main(){
	int n, m;
	cin >> n >> m;
	int s, t, k;
	cin >> s >> t >> k;
	s--; t--;
	Dijkstra<int> graph(n);
	rep(i, m){
		int u, v;
		cin >> u >> v;
		u--; v--;
		graph.add_edge(u, v, 1);
		graph.add_edge(v, u, 1);
	}
	int dist = graph.get_dist(s, t);
	if(dist >= INF){
		cout << "Unknown\n";
	}else{
		int diff = abs(dist - k);
		if(diff % 2) cout << "No\n";
		else{
			if(dist <= k) cout << "Yes\n";
			else cout << "Unknown\n";
		}
	}
	return 0;
}
0