結果

問題 No.1190 Points
ユーザー achapiachapi
提出日時 2023-04-23 11:38:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 2,466 ms
コンパイル使用メモリ 210,104 KB
実行使用メモリ 14,828 KB
最終ジャッジ日時 2024-04-25 08:48:52
合計ジャッジ時間 7,849 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 133 ms
9,860 KB
testcase_04 AC 88 ms
8,260 KB
testcase_05 AC 148 ms
9,948 KB
testcase_06 AC 102 ms
10,140 KB
testcase_07 AC 199 ms
12,768 KB
testcase_08 AC 270 ms
14,724 KB
testcase_09 AC 256 ms
13,496 KB
testcase_10 AC 278 ms
14,828 KB
testcase_11 AC 174 ms
10,504 KB
testcase_12 AC 240 ms
13,756 KB
testcase_13 AC 157 ms
9,088 KB
testcase_14 AC 26 ms
7,300 KB
testcase_15 AC 256 ms
13,344 KB
testcase_16 AC 15 ms
5,376 KB
testcase_17 AC 234 ms
12,828 KB
testcase_18 AC 98 ms
6,400 KB
testcase_19 AC 21 ms
8,108 KB
testcase_20 AC 138 ms
7,936 KB
testcase_21 AC 36 ms
6,592 KB
testcase_22 AC 48 ms
9,156 KB
testcase_23 AC 266 ms
13,792 KB
testcase_24 AC 261 ms
13,664 KB
testcase_25 AC 110 ms
10,340 KB
testcase_26 AC 101 ms
10,332 KB
testcase_27 AC 112 ms
10,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
	int n, m, p;
	cin >> n >> m >> p;
	int S, G;
	cin >> S >> G;
	S--;
	G--;
	Graph g(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);
	}
	vector<vector<int>> d(2, vector<int> (n, 1 << 30));
	vector<vector<int>> d2(2, vector<int> (n, 1 << 30));
	queue<pair<int, int>> q;
	q.push({S, 0});
	d[0][S] = 0;
	while (!q.empty()){
		auto [v, c] = q.front();
		q.pop();
		c++;
		for (int i : g[v]){
			if (d[c % 2][i] > c){
				d[c % 2][i] = c;
				q.push({i, c});
			}
		}
	}
	q.push({G, 0});
	d2[0][G] = 0;
	while (!q.empty()){
		auto [v, c] = q.front();
		q.pop();
		c++;
		for (int i : g[v]){
			if (d2[c % 2][i] > c){
				d2[c % 2][i] = c;
				q.push({i, c});
			}
		}
	}
	set<int> ans;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 2; j++){
			for (int k = 0; k < 2; k++){
				if (d[j][i] == (1 << 30) or d2[k][i] == (1 << 30)){
					continue;
				}
				int c = p - d[j][i] - d2[k][i];
				if (c >= 0 and c % 2 == 0){
					ans.insert(i);
				}
			}
		}
	}
	if (ans.empty()){
		cout << -1 << endl;
		return 0;
	}
	cout << ans.size() << endl;
	for (int i : ans){
		cout << i + 1 << endl;
	}
}
0