77932024-01-11 10:18:09csaron71A lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 3/5014ms9996 KiB
#include <bits/stdc++.h>

using namespace std;


int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int> > elek(m, vector<int>());
    for (int i=0; i<n; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        elek[x].push_back(y);
        elek[y].push_back(x);
    }

    queue<pair<int, int> > sor;
    sor.push({0, m-1});
    vector<int> ertekek(m, -1);

    while (sor.size()>0) {

        int tav=sor.front().first;
        int elso=sor.front().second;
        sor.pop();
        if (ertekek[elso]!=-1) {
            continue;
        }
        //cout << elso << " " << tav << "\n";
        ertekek[elso]=tav;
        for (int sz : elek[elso]) {
            sor.push({tav+1, sz});
        }
    }
    if (ertekek[0]==-1) {
        cout << "-1";
    }
    else {
        cout << ertekek[0]-1 << "\n";
        int szam=ertekek[0];
        for (int i=1; i<m; i++) {
                if (szam==0) {
                    break;
                }
            if (ertekek[i]<=ertekek[0] && ertekek[i]!=-1) {
                cout << i+1 << " ";
                szam--;
            }
        }
    }


    return 0;
}
SubtaskSumTestVerdictTimeMemory
base3/50
1Wrong answer0/03ms1812 KiB
2Wrong answer0/013ms8552 KiB
3Accepted1/13ms2264 KiB
4Accepted1/13ms2476 KiB
5Partially correct1/23ms2688 KiB
6Wrong answer0/23ms2772 KiB
7Wrong answer0/24ms2980 KiB
8Wrong answer0/24ms3116 KiB
9Wrong answer0/24ms3160 KiB
10Wrong answer0/24ms3572 KiB
11Wrong answer0/27ms5212 KiB
12Wrong answer0/28ms5244 KiB
13Wrong answer0/24ms3860 KiB
14Wrong answer0/24ms5456 KiB
15Wrong answer0/26ms6208 KiB
16Wrong answer0/28ms6420 KiB
17Wrong answer0/210ms8712 KiB
18Wrong answer0/210ms8732 KiB
19Wrong answer0/212ms9120 KiB
20Wrong answer0/212ms9380 KiB
21Wrong answer0/214ms9768 KiB
22Wrong answer0/213ms9996 KiB
23Wrong answer0/212ms8056 KiB
24Wrong answer0/213ms8576 KiB
25Wrong answer0/213ms9364 KiB
26Wrong answer0/213ms9492 KiB
27Wrong answer0/213ms9880 KiB
28Wrong answer0/213ms9908 KiB