Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
- #pragma GCC optimize 03
- #pragma GCC optimize("unroll-loops")
- #include <iostream>
- #include <algorithm>
- #include <iterator>
- #include <iomanip>
- #include <cmath>
- #include <ctime>
- #include <vector>
- #include <deque>
- #include <queue>
- #include <set>
- #include <map>
- #include <stack>
- #include <string>
- #include <random>
- #include <numeric>
- #include <unordered_set>
- typedef long long ll;
- typedef long double lb;
- #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- #define file_in freopen("input.txt", "r", stdin);
- #define file_in_out freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
- #define pii pair<int, int>
- #define all(x) (x).begin(), (x).end()
- #define fi first
- #define se second
- using namespace std;
- template<typename T>
- istream& operator>>(istream &in, vector<T> &v) {
- for (auto &it : v) {
- in >> it;
- }
- return in;
- }
- template<typename T>
- ostream& operator<<(ostream &out, vector<T> &v) {
- if (!v.empty()) {
- out << v.front();
- for (int i = 1; i < v.size(); ++i) {
- out << " " << v[i];
- }
- }
- return out;
- }
- template<typename T>
- istream& operator>>(istream &in, pair<T, T> &v) {
- in >> v.x >> v.y;
- return in;
- }
- template<typename T>
- ostream& operator<<(ostream &out, pair<T, T> &v) {
- out << v.x << " " << v.y;
- return out;
- }
- const int INF = 2e9;
- int s;
- vector<char> spec;
- vector<int> dist;
- vector<vector<pair<int, int>>> g;
- void bfs(int st) {
- queue<pair<int, int>> q;
- q.push({st, s});
- while (!q.empty()) {
- int v = q.front().fi;
- int now = q.front().se;
- q.pop();
- if (spec[v] == 1) {
- dist[v] = 0;
- now = s;
- }
- for (auto uu : g[v]) {
- int u = uu.fi, w = uu.se;
- if (dist[u] > dist[v] + w && now >= w) {
- dist[u] = dist[v] + w;
- q.push({u, now - w});
- }
- }
- }
- }
- int main() {
- fast
- // file_in
- // file_in_out
- // int start = clock();
- int n, m, k;
- cin >> n >> m >> k >> s;
- g.resize(n); spec.resize(n, 0); dist.resize(n, INF);
- int v, u, w;
- for (int i = 0; i < m; ++i) {
- cin >> v >> u >> w;
- --v; --u;
- g[v].push_back({u, w});
- g[u].push_back({v, w});
- }
- for (int i = 0; i < k; ++i) {
- cin >> v; --v;
- spec[v] = 1;
- }
- bfs(0);
- int cnt = 0;
- for (int i = 0; i < n; ++i) {
- if (dist[i] != INF) {
- ++cnt;
- }
- }
- cout << cnt << '\n';
- for (int i = 0; i < n; ++i) {
- if (dist[i] != INF) {
- cout << i + 1 << ' ';
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment