結果

問題 No.1190 Points
ユーザー achapiachapi
提出日時 2023-04-23 10:18:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 989 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 202,920 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-04-25 07:55:29
合計ジャッジ時間 6,117 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 100 ms
8,192 KB
testcase_04 AC 70 ms
7,424 KB
testcase_05 AC 124 ms
7,296 KB
testcase_06 AC 76 ms
9,088 KB
testcase_07 AC 155 ms
9,984 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

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<int> d(n, -1);
	d[S] = 0;
	queue<int> q;
	q.push(S);
	while (!q.empty()){
		int v = q.front();
		q.pop();
		for (int i : g[v]){
			if (d[i] == -1){
				d[i] = d[v] + 1;
				q.push(i);
			}
		}
	}
	vector<int> d2(n, -1);
	d2[G] = 0;
	queue<int> q2;
	q2.push(G);
	while (!q2.empty()){
		int v = q2.front();
		q2.pop();
		for (int i : g[v]){
			if (d2[i] == -1){
				d2[i] = d2[v] + 1;
				q2.push(i);
			}
		}
	}
	vector<int> ans;
	for (int i = 0; i < n; i++){
		int c = p - (d[i] + d2[i]);
		if (c >= 0 and c % 2 == 0){
			ans.push_back(i);
		}
	}
	if (ans.empty()){
		cout << -1 << endl;
		return 0;
	}
	cout << ans.size() << endl;
	for (int i : ans){
		cout << i + 1 << endl;
	}
}
0