結果

問題 No.1190 Points
ユーザー akun0716akun0716
提出日時 2020-10-17 08:54:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 2,690 bytes
コンパイル時間 2,896 ms
コンパイル使用メモリ 93,320 KB
実行使用メモリ 13,128 KB
最終ジャッジ日時 2023-09-28 07:22:53
合計ジャッジ時間 4,723 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 36 ms
10,204 KB
testcase_04 AC 28 ms
9,248 KB
testcase_05 AC 30 ms
8,968 KB
testcase_06 AC 43 ms
11,532 KB
testcase_07 AC 48 ms
12,792 KB
testcase_08 AC 47 ms
12,768 KB
testcase_09 AC 51 ms
12,548 KB
testcase_10 AC 49 ms
12,696 KB
testcase_11 AC 41 ms
10,200 KB
testcase_12 AC 52 ms
12,680 KB
testcase_13 AC 36 ms
9,164 KB
testcase_14 AC 12 ms
8,100 KB
testcase_15 AC 56 ms
13,052 KB
testcase_16 AC 8 ms
4,704 KB
testcase_17 AC 50 ms
12,436 KB
testcase_18 AC 30 ms
6,956 KB
testcase_19 AC 11 ms
9,144 KB
testcase_20 AC 36 ms
8,204 KB
testcase_21 AC 16 ms
6,960 KB
testcase_22 AC 21 ms
10,168 KB
testcase_23 AC 59 ms
13,128 KB
testcase_24 AC 57 ms
13,096 KB
testcase_25 AC 46 ms
12,212 KB
testcase_26 AC 37 ms
12,044 KB
testcase_27 AC 47 ms
12,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;

int N, M, P, s, g;
vector<VI> G;
int dp1[100010][2];
int dp2[100010][2];


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> M >> P >> s >> g;
	G.resize(N);
	s--;
	g--;
	REP(i, M) {
		int v, u; cin >> u >> v;
		u--;
		v--;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	REP(i, N) dp1[i][0] = dp1[i][1] = dp2[i][0] = dp2[i][1] = INF;
	queue<int>Q;
	Q.push(s);
	dp1[s][0] = 0;
	while (!Q.empty()) {
		int now = Q.front();
		Q.pop();
		//cout << now << endl;
		fore(to,G[now]) {
			bool F = false;//pushするか
			if (dp1[now][0] + 1 < dp1[to][1]) {
				dp1[to][1] = dp1[now][0] + 1;
				F = true;
			}
			if (dp1[now][1] + 1 < dp1[to][0]) {
				dp1[to][0] = dp1[now][1] + 1;
				F = true;
			}
			if (F)Q.push(to);
		}
	}

	Q.push(g);
	dp2[g][0] = 0;
	while (!Q.empty()) {
		int now = Q.front();
		Q.pop();

		fore(to, G[now]) {
			bool F = false;//pushするか
			if (dp2[now][0] + 1 < dp2[to][1]) {
				dp2[to][1] = dp2[now][0] + 1;
				F = true;
			}
			if (dp2[now][1] + 1 < dp2[to][0]) {
				dp2[to][0] = dp2[now][1] + 1;
				F = true;
			}
			if (F)Q.push(to);
		}
	}
	REP(i, N) {
		//cout << dp1[i][0] << " " << dp1[i][1] << " " << dp2[i][0] << " " << dp2[i][1] << endl;
	}
	VI ans;
	REP(i, N) {
		bool F = false;//pushできるか
		REP(j, 2)REP(k, 2) {
			if ((P >= dp1[i][j] + dp2[i][k]) && ((P - dp1[i][j] - dp2[i][k]) % 2 == 0)) {
				F = true;
			}
		}
		if (F)ans.push_back(i);
	}
	
	if (ans.size() == 0) {
		cout << -1 << endl;
		return 0;
	}
	SORT(ans);
	cout << ans.size() << endl;
	fore(i, ans)cout << i + 1 << '\n';

	return 0;
}

0