94792024-02-22 10:39:32csaron71A lehető legkevesebb metróval utazás (40 pont)cpp17Wrong answer 16/4061ms63892 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m, kezd, veg;
    cin >> n >> m >> kezd >> veg;
    kezd--;
    veg--;
    vector<vector<int> > graph(m, vector<int>());
    for (int i=0; i<n; i++) {
        int x;
        cin >> x;
        vector<int> epp;
        for (int i=0; i<x; i++) {
            int y;
            cin >> y;
            y--;
            epp.push_back(y);
        }
        for (int q=0; q<x; q++) {
            for (int j=q+1; j<x; j++) {
                graph[epp[q]].push_back(epp[j]);
                graph[epp[j]].push_back(epp[q]);
            }
        }
    }

    queue<pair<int, int> > sor;
    vector<bool> volt(m, false);
    vector<int> tav(m, -1);
    sor.push({kezd, 0});
    tav[kezd]=0;

    while (sor.size()>0) {
        int elso=sor.front().first;
        int hany=sor.front().second;
        sor.pop();
        if (volt[elso]==true) continue;
        tav[elso]=hany;
        volt[elso]=true;

        for (int sz : graph[elso]) {
            if (volt[sz]!=true) {
                sor.push({sz, hany+1});
            }
        }
    }
/*
    for (int sz : tav) {
        cout << sz << " ";
    }*/
    cout << tav[veg];
}
SubtaskSumTestVerdictTimeMemory
base16/40
1Wrong answer0/03ms1812 KiB
2Wrong answer0/028ms13840 KiB
3Partially correct1/22ms2092 KiB
4Partially correct1/23ms2220 KiB
5Partially correct1/24ms5328 KiB
6Accepted2/23ms2528 KiB
7Partially correct1/226ms18484 KiB
8Partially correct1/237ms35240 KiB
9Runtime error0/261ms63892 KiB
10Partially correct1/243ms38872 KiB
11Partially correct1/28ms7296 KiB
12Partially correct1/232ms18292 KiB
13Partially correct1/232ms18372 KiB
14Partially correct1/228ms16308 KiB
15Runtime error0/254ms63628 KiB
16Runtime error0/250ms63620 KiB
17Runtime error0/250ms63596 KiB
18Runtime error0/252ms63588 KiB
19Partially correct1/214ms8668 KiB
20Partially correct1/224ms13548 KiB
21Partially correct1/28ms5696 KiB
22Partially correct1/228ms15328 KiB