結果

問題 No.1190 Points
ユーザー achapiachapi
提出日時 2023-04-23 10:12:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,326 bytes
コンパイル時間 2,784 ms
コンパイル使用メモリ 209,000 KB
実行使用メモリ 816,000 KB
最終ジャッジ日時 2024-04-25 07:51:36
合計ジャッジ時間 6,376 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 149 ms
9,472 KB
testcase_07 WA -
testcase_08 MLE -
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>>;

set<int> ans;
set<int> s;
bool f[101010];
void dfs(Graph &g, vector<int> d, int v){
	if (s.find(v) != s.end()){
		for (int i : d){
			ans.insert(i);
		}
	}
	for (int i : g[v]){
		if (!f[i]){
			f[i] = true;
			d.push_back(i);
			dfs(g, d, i);
			d.pop_back();
		}
	}
}

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 (p % (d[i] + d2[i]) == 0){
			s.insert(i);
		}
	}
	vector<int> D;
	D.push_back(S);
	dfs(g, D, S);
	D.clear();
	D.push_back(G);
	memset(f, 0, sizeof(f));
	dfs(g, D, G);
	if (ans.empty()){
		cout << -1 << endl;
		return 0;
	}
	cout << ans.size() << endl;
	for (int i : ans){
		cout << i + 1 << endl;
	}
}
0