64632023-12-02 16:49:20111Tom és Jerry2 (60)cpp17Wrong answer 21/6045ms15088 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double

#define pii pair<int, int>

#define INF 1e9

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef CB
	freopen("be1.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	int N, M, T, DB, E;
	cin >> N >> M >> T >> DB >> E;
	vector<vector<int>> gj(N + 1);
	vector<vector<int>> gt(N + 1);
	for (int i = 0; i < M; i++) {
		int a, b, s;
		cin >> a >> b >> s;
		gj[a].push_back(b);
		gj[b].push_back(a);
		if (s == 2) {
			gt[a].push_back(b);
			gt[b].push_back(a);
		}
	}
	deque<int> q;
	vector<int> dt(N + 1, INF);
	dt[T] = 0;
	q.push_back(T);
	while (!q.empty()) {
		int i = q.front();
		q.pop_front();
		for (int j : gt[i]) {
			if (dt[j] == INF && j != E) {
				dt[j] = dt[i] + 1;
				q.push_back(j);
			}
		}
	}
	vector<int> v(N + 1);
	vector<int> w(N + 1);
	v[E] = 1;
	q.push_back(E);
	while (!q.empty()) {
		int i = q.front();
		q.pop_front();
		for (int j : gj[i]) {
			int k = (i == E) ? j : w[i];
			if (v[j] == 0) {
				v[j] = v[i] + 1;
				w[j] = k;
				q.push_back(j);
			}
			else {
				if (w[j] != k) {
					w[j] = j;
				}
			}
		}
	}
	while (DB--) {
		int i;
		cin >> i;
		if (dt[w[i]] <= v[i] - v[w[i]]) {
			cout << w[i] << '\n';
		}
		else {
			cout << 0 << '\n';
		}
	}
	return 0;
}

SubtaskSumTestVerdictTimeMemory
base21/60
1Accepted0/03ms1824 KiB
2Wrong answer0/09ms5004 KiB
3Wrong answer0/23ms2236 KiB
4Accepted2/23ms2340 KiB
5Wrong answer0/23ms2556 KiB
6Wrong answer0/33ms2644 KiB
7Wrong answer0/23ms2916 KiB
8Wrong answer0/23ms3092 KiB
9Wrong answer0/23ms2928 KiB
10Wrong answer0/33ms3120 KiB
11Wrong answer0/33ms3396 KiB
12Wrong answer0/34ms3896 KiB
13Wrong answer0/37ms4728 KiB
14Wrong answer0/38ms5276 KiB
15Accepted3/38ms5424 KiB
16Wrong answer0/310ms5976 KiB
17Accepted3/39ms6564 KiB
18Accepted3/318ms9232 KiB
19Wrong answer0/430ms11320 KiB
20Wrong answer0/445ms15088 KiB
21Accepted5/526ms11960 KiB
22Accepted5/526ms11568 KiB