結果

問題 No.1190 Points
ユーザー achapiachapi
提出日時 2023-04-23 10:50:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,373 bytes
コンパイル時間 2,708 ms
コンパイル使用メモリ 209,088 KB
実行使用メモリ 24,320 KB
最終ジャッジ日時 2024-04-25 08:17:33
合計ジャッジ時間 8,447 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 187 ms
11,008 KB
testcase_04 AC 115 ms
8,320 KB
testcase_05 AC 227 ms
12,160 KB
testcase_06 AC 127 ms
9,216 KB
testcase_07 AC 306 ms
14,720 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 26 ms
6,656 KB
testcase_15 WA -
testcase_16 AC 19 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 18 ms
7,168 KB
testcase_20 WA -
testcase_21 AC 43 ms
6,656 KB
testcase_22 AC 47 ms
7,936 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 95 ms
9,472 KB
testcase_26 AC 96 ms
9,216 KB
testcase_27 AC 97 ms
9,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

set<int> ans;
set<int> s;
set<int> D;

bool f[101010];
void dfs(Graph &g, int v){
	if (s.find(v) != s.end()){
		for (int i : D){
			ans.insert(i);
		}
		D.clear();
	}
	for (int i : g[v]){
		if (!f[i]){
			f[i] = true;
			D.insert(i);
			dfs(g, i);
			D.erase(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);
	}
	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);
			}
		}
	}
	for (int i = 0; i < n; i++){
		if (d[i] == -1 or d2[i] == -1){
			continue;
		}
		int c = p - d[i] - d2[i];
		if (c >= 0 and c % 2 == 0){
			s.insert(i);
			ans.insert(i);
		}
	}
	s.erase(S);
	s.erase(G);
	D.insert(S);
	f[S] = true;
	dfs(g, S);

	if (ans.empty()){
		cout << -1 << endl;
		return 0;
	}
	cout << ans.size() << endl;
	for (int i : ans){
		cout << i + 1 << endl;
	}
}
0