結果

問題 No.1190 Points
ユーザー achapiachapi
提出日時 2023-04-23 11:28:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,240 bytes
コンパイル時間 2,070 ms
コンパイル使用メモリ 202,976 KB
実行使用メモリ 27,776 KB
最終ジャッジ日時 2024-04-25 08:41:59
合計ジャッジ時間 6,764 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 111 ms
9,856 KB
testcase_04 AC 69 ms
8,320 KB
testcase_05 AC 131 ms
9,856 KB
testcase_06 AC 80 ms
9,856 KB
testcase_07 AC 173 ms
12,800 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int d[2][101010];
int d2[2][101010];

void dfs(Graph &g, int c, int v){
	for (int i : g[v]){
		if (d[(c + 1) % 2][i] > c + 1){
			d[(c + 1) % 2][i] = c + 1;
			dfs(g, c + 1, i);
		}
	}
}

void dfs2(Graph &g, int c, int v){
	for (int i : g[v]){
		if (d2[(c + 1) % 2][i] > c + 1){
			d2[(c + 1) % 2][i] = c + 1;
			dfs2(g, c + 1, i);
		}
	}
}

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);
	}
	for (int i = 0; i < 2; i++){
		for (int j = 0; j < n; j++){
			d[i][j] = 1 << 30;
			d2[i][j] = 1 << 30;
		}
	}
	d[0][S] = 0;
	dfs(g, 0, S);
	d2[0][G] = 0;
	dfs2(g, 0, G);
	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