結果
| 問題 | 
                            No.1190 Points
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Example0911
                         | 
                    
| 提出日時 | 2020-08-24 18:32:12 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 251 ms / 2,000 ms | 
| コード長 | 1,373 bytes | 
| コンパイル時間 | 1,863 ms | 
| コンパイル使用メモリ | 180,384 KB | 
| 実行使用メモリ | 25,760 KB | 
| 最終ジャッジ日時 | 2024-11-06 10:33:05 | 
| 合計ジャッジ時間 | 6,992 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
#include "bits/stdc++.h"
using namespace std;
// コンテスト中のみ
//#define int long long
#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
//#define P pair<ll,ll>
#define ld long double
ll INF = (1LL << 60);
int MOD = 1000000007;
ll N, M, P, S, G;
vector<vector<ll>> bfs(ll s, vector<vector<ll>>g) {
	vector<vector<ll>>dist(N, vector<ll>(2, INF));
	dist[s][0] = 0;
	queue<pair<ll, ll>>q;
	q.push({ s,0 });
	while (!q.empty()) {
		pair<ll, ll> p = q.front(); q.pop();
		for (auto nv : g[p.first]) {
			if (dist[nv][p.second ^ 1] == INF) {
				dist[nv][p.second ^ 1] = dist[p.first][p.second] + 1;
				q.push({ nv,p.second ^ 1 });
			}
		}
	}
	return dist;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> N >> M >> P >> S >> G; S--; G--;
	vector<vector<ll>>g(N);
	rep(i, M) {
		ll a, b; cin >> a >> b; a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	vector<vector<ll>>ds = bfs(S, g), dg = bfs(G, g);
	vector<ll>ans;
	rep(i, N) {
		ll even = min(ds[i][0] + dg[i][0], ds[i][1] + dg[i][1]);
		ll odd = min(ds[i][0] + dg[i][1], ds[i][1] + dg[i][0]);
		if (P % 2) {
			if (odd <= P) {
				ans.push_back(i);
			}
		}
		else {
			if (even <= P) {
				ans.push_back(i);
			}
		}
	}
	if (ans.empty()) { cout << -1 << endl; return 0; }
	cout << ans.size() << endl;
	for (auto x : ans)cout << x + 1 << endl;
	return 0;
}
            
            
            
        
            
Example0911