結果

問題 No.1190 Points
ユーザー tkmst201tkmst201
提出日時 2021-02-11 09:58:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 2,269 ms
コンパイル使用メモリ 212,324 KB
実行使用メモリ 20,096 KB
最終ジャッジ日時 2023-09-24 22:59:52
合計ジャッジ時間 6,130 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 71 ms
15,440 KB
testcase_04 AC 56 ms
14,192 KB
testcase_05 AC 53 ms
12,852 KB
testcase_06 AC 102 ms
18,540 KB
testcase_07 AC 113 ms
19,668 KB
testcase_08 AC 100 ms
20,028 KB
testcase_09 AC 106 ms
18,564 KB
testcase_10 AC 103 ms
20,096 KB
testcase_11 AC 68 ms
14,236 KB
testcase_12 AC 110 ms
19,536 KB
testcase_13 AC 61 ms
12,080 KB
testcase_14 AC 26 ms
13,268 KB
testcase_15 AC 125 ms
19,604 KB
testcase_16 AC 12 ms
6,284 KB
testcase_17 AC 119 ms
19,004 KB
testcase_18 AC 42 ms
7,584 KB
testcase_19 AC 28 ms
16,640 KB
testcase_20 AC 53 ms
10,108 KB
testcase_21 AC 29 ms
10,708 KB
testcase_22 AC 43 ms
17,100 KB
testcase_23 AC 138 ms
19,984 KB
testcase_24 AC 117 ms
20,016 KB
testcase_25 AC 93 ms
19,480 KB
testcase_26 AC 66 ms
19,340 KB
testcase_27 AC 95 ms
19,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N, M, P, S, G;
	cin >> N >> M >> P >> S >> G;
	--S; --G;
	
	vector<vector<int>> g(N);
	REP(i, M) {
		int u, v;
		scanf("%d %d", &u, &v);
		--u; --v;
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	
	auto solve = [&](int s) {
		vector dist(N, vector(2, INF)); // [i][j] := j=0(even), j=1(odd)
		queue<pii> que; // u, d
		que.emplace(s, 0);
		dist[s][0] = 0;
		while (!que.empty()) {
			auto [u, d] = que.front();
			que.pop();
			for (int v : g[u]) if (chmin(dist[v][(d + 1) & 1], d + 1)) que.emplace(v, d + 1);
		}
		return dist;
	};
	
	auto d1 = solve(S), d2 = solve(G);
	
	vector<int> ans;
	REP(i, N) {
		bool ok = false;
		REP(j, 2) REP(k, 2) {
			if (d1[i][j] == INF || d2[i][k] == INF) continue;
			const int d = d1[i][j] + d2[i][k];
			ok |= d <= P && (P - d) % 2 == 0;
		}
		if (ok) ans.emplace_back(i);
	}
	
	if (ans.empty()) puts("-1");
	else {
		cout << ans.size() << endl;
		for (int i : ans) printf("%d\n", i + 1);
	}
}
0