結果

問題 No.1190 Points
ユーザー leaf_1415leaf_1415
提出日時 2020-08-22 14:21:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,729 bytes
コンパイル時間 1,042 ms
コンパイル使用メモリ 88,700 KB
実行使用メモリ 19,188 KB
最終ジャッジ日時 2024-04-23 08:41:44
合計ジャッジ時間 4,506 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,412 KB
testcase_01 AC 5 ms
9,284 KB
testcase_02 AC 5 ms
10,740 KB
testcase_03 AC 80 ms
16,580 KB
testcase_04 AC 63 ms
15,428 KB
testcase_05 AC 61 ms
15,168 KB
testcase_06 AC 113 ms
17,864 KB
testcase_07 AC 119 ms
18,624 KB
testcase_08 AC 89 ms
18,436 KB
testcase_09 AC 98 ms
18,592 KB
testcase_10 AC 104 ms
18,440 KB
testcase_11 AC 67 ms
16,568 KB
testcase_12 AC 97 ms
18,544 KB
testcase_13 AC 78 ms
16,216 KB
testcase_14 AC 23 ms
13,124 KB
testcase_15 AC 129 ms
19,056 KB
testcase_16 AC 14 ms
11,464 KB
testcase_17 AC 114 ms
18,408 KB
testcase_18 AC 51 ms
14,584 KB
testcase_19 AC 16 ms
12,808 KB
testcase_20 AC 70 ms
16,040 KB
testcase_21 AC 30 ms
12,996 KB
testcase_22 AC 42 ms
15,176 KB
testcase_23 AC 134 ms
19,188 KB
testcase_24 AC 139 ms
19,172 KB
testcase_25 AC 115 ms
18,248 KB
testcase_26 AC 94 ms
18,244 KB
testcase_27 AC 110 ms
18,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353

using namespace std;
typedef pair<llint, llint> P;

llint n, m, p;
llint s, g;
vector<llint> G[200005];
llint distS[200005], distG[200005];

void bfs(vector<llint> G[], int S, llint dist[])
{
	queue<int> Q;
	Q.push(S);
	
	for(int i = 1; i <= 2*n; i++) dist[i] = inf;
	dist[S] = 0;
	
	while(Q.size()){
		int v = Q.front();
		Q.pop();
		for(int i = 0; i < G[v].size(); i++){
			if(dist[G[v][i]] < inf/2) continue;
			Q.push(G[v][i]);
			dist[G[v][i]] = dist[v] + 1;
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> p;
	cin >> s >> g;
	
	llint u, v;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		G[u].push_back(v+n);
		G[v].push_back(u+n);
		G[u+n].push_back(v);
		G[v+n].push_back(u);
	}
	
	bfs(G, s, distS);
	bfs(G, g, distG);
	
	if(distS[p%2*n + g] > p){
		cout << -1 << endl;
		return 0;
	}
	
	vector<llint> ans;
	for(int i = 1; i <= n; i++){
		bool flag = false;
		if(distS[i] + distG[p%2*n+i] <= p) flag = true;
		if(distS[n+i] + distG[(p+1)%2*n+i] <= p) flag = true;
		if(flag) ans.push_back(i);
	}
	
	cout << ans.size() << "\n";
	for(int i = 0; i < ans.size(); i++) cout << ans[i] << "\n";
	flush(cout);
	
	return 0;
}
0