91872024-02-17 16:58:54xxxA lehető legkevesebb metróval utazás (40 pont)cpp17Wrong answer 0/40495ms15300 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
	int n, m, ind, erk;
	cin >> n >> m >> ind >> erk;
	vector<vector<int> > megall(m+1);
	vector<vector<bool> > el(n+1, vector<bool>(n+1, false));
	for(int i = 0; i < n; i++) {
		int db;
		cin >> db;
		for(int j = 0; j < db; j++) {
			int x;
			cin >> x;
			megall[x].push_back(i);
		}
	}

	

	for(int i = 1; i <= m; i++) {
		if (megall[i].size() > 1) {
			for(int j = 0; j < megall[i].size(); j++) {
				for(int k = j+1; k < megall[i].size(); k++) {
					el[megall[i][j]][megall[i][k]] = 1;
					el[megall[i][k]][megall[i][j]] = 1;
				}
			}
		}
	}
	queue<int> q;
	vector<int> tav(n+1, -1), parent(n+1, -1);

	for(int i : megall[ind]) {
		q.push(i);
		tav[i] = 1;
	}

	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(int i = 0; i < n; i++) {
			if (el[u][i]) {
				if (tav[i] == -1) {
					tav[i] = tav[u]+1;
					parent[i] = u;
					q.push(i);
				}
			}
		}
	}
	return 0;

	int ans = INT_MAX, mini = 0;
	for(int i : megall[erk]) {
		if (ans > tav[i]) {
			ans = tav[i];
			mini = i;
		}
	}
	cout << ans << '\n';

	vector<int> ansv;
	
	while(ans--) {
		ansv.push_back(mini);
		mini = parent[mini];
	}
	reverse(ansv.begin(), ansv.end());
	for(int x : ansv) {
		cout << x+1 << ' ';
	}

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Wrong answer0/03ms1824 KiB
2Wrong answer0/04ms3044 KiB
3Wrong answer0/23ms2152 KiB
4Wrong answer0/23ms2136 KiB
5Wrong answer0/23ms2520 KiB
6Wrong answer0/23ms2540 KiB
7Wrong answer0/23ms2888 KiB
8Wrong answer0/23ms2924 KiB
9Wrong answer0/24ms3444 KiB
10Wrong answer0/24ms3632 KiB
11Wrong answer0/23ms3316 KiB
12Wrong answer0/26ms3908 KiB
13Wrong answer0/26ms3908 KiB
14Wrong answer0/24ms4064 KiB
15Wrong answer0/2492ms15216 KiB
16Wrong answer0/2493ms15028 KiB
17Wrong answer0/2492ms15124 KiB
18Wrong answer0/2495ms15300 KiB
19Wrong answer0/24ms3744 KiB
20Wrong answer0/24ms4092 KiB
21Wrong answer0/24ms3896 KiB
22Wrong answer0/24ms4340 KiB