結果

問題 No.1190 Points
ユーザー Example0911Example0911
提出日時 2020-08-24 18:32:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 1,373 bytes
コンパイル時間 2,005 ms
コンパイル使用メモリ 175,480 KB
実行使用メモリ 25,760 KB
最終ジャッジ日時 2024-04-24 03:42:11
合計ジャッジ時間 7,782 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 136 ms
19,312 KB
testcase_04 AC 98 ms
17,996 KB
testcase_05 AC 141 ms
16,228 KB
testcase_06 AC 141 ms
24,156 KB
testcase_07 AC 219 ms
25,292 KB
testcase_08 AC 230 ms
24,980 KB
testcase_09 AC 238 ms
23,296 KB
testcase_10 AC 237 ms
25,080 KB
testcase_11 AC 161 ms
18,220 KB
testcase_12 AC 221 ms
24,356 KB
testcase_13 AC 149 ms
15,860 KB
testcase_14 AC 39 ms
16,292 KB
testcase_15 AC 264 ms
25,148 KB
testcase_16 AC 19 ms
7,400 KB
testcase_17 AC 237 ms
24,128 KB
testcase_18 AC 79 ms
10,572 KB
testcase_19 AC 39 ms
19,672 KB
testcase_20 AC 118 ms
13,492 KB
testcase_21 AC 41 ms
13,272 KB
testcase_22 AC 65 ms
21,508 KB
testcase_23 AC 268 ms
25,624 KB
testcase_24 AC 268 ms
25,756 KB
testcase_25 AC 136 ms
25,756 KB
testcase_26 AC 105 ms
25,240 KB
testcase_27 AC 134 ms
25,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

// コンテスト中のみ
//#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
//#define P pair<ll,ll>
#define ld long double
ll INF = (1LL << 60);
int MOD = 1000000007;

ll N, M, P, S, G;

vector<vector<ll>> bfs(ll s, vector<vector<ll>>g) {
	vector<vector<ll>>dist(N, vector<ll>(2, INF));
	dist[s][0] = 0;
	queue<pair<ll, ll>>q;
	q.push({ s,0 });
	while (!q.empty()) {
		pair<ll, ll> p = q.front(); q.pop();
		for (auto nv : g[p.first]) {
			if (dist[nv][p.second ^ 1] == INF) {
				dist[nv][p.second ^ 1] = dist[p.first][p.second] + 1;
				q.push({ nv,p.second ^ 1 });
			}
		}
	}
	return dist;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> N >> M >> P >> S >> G; S--; G--;
	vector<vector<ll>>g(N);
	rep(i, M) {
		ll a, b; cin >> a >> b; a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vector<vector<ll>>ds = bfs(S, g), dg = bfs(G, g);
	vector<ll>ans;
	rep(i, N) {
		ll even = min(ds[i][0] + dg[i][0], ds[i][1] + dg[i][1]);
		ll odd = min(ds[i][0] + dg[i][1], ds[i][1] + dg[i][0]);
		if (P % 2) {
			if (odd <= P) {
				ans.push_back(i);
			}
		}
		else {
			if (even <= P) {
				ans.push_back(i);
			}
		}
	}
	if (ans.empty()) { cout << -1 << endl; return 0; }
	cout << ans.size() << endl;
	for (auto x : ans)cout << x + 1 << endl;
	return 0;
}
0