78112024-01-11 10:51:33csaron71A lehető legkevesebb átszállás (50 pont)cpp17Accepted 50/5010ms5000 KiB
#include <bits/stdc++.h>

using namespace std;


int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, pair<int, int> > > vasut;
    for (int i=0; i<n; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        if (x<y) {
            swap(x, y);
        }
        vasut.push_back({x, {y, i+1}});
    }
    sort(vasut.begin(), vasut.end());
    reverse(vasut.begin(), vasut.end());
    int epp=0;
    vector<int> utvonal;
    int valtozas=1;
    while (valtozas!=epp) {
        valtozas=epp;
        for (int j=0; j<n; j++) {
            if (vasut[j].second.first<=epp && vasut[j].first>epp) {
                epp=vasut[j].first;
                utvonal.push_back(vasut[j].second.second);
                break;
            }
        }
    }
    if (epp==m-1) {
        cout << utvonal.size()-1 << "\n";
        for (int sz : utvonal) {
            cout << sz << " ";
        }
    }
    else {
        cout << "-1";
    }


    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1816 KiB
2Accepted0/010ms2588 KiB
3Accepted1/13ms2308 KiB
4Accepted1/13ms2520 KiB
5Accepted2/23ms2668 KiB
6Accepted2/23ms2760 KiB
7Accepted2/23ms2744 KiB
8Accepted2/24ms3020 KiB
9Accepted2/24ms3172 KiB
10Accepted2/24ms3164 KiB
11Accepted2/26ms3472 KiB
12Accepted2/26ms3796 KiB
13Accepted2/23ms3644 KiB
14Accepted2/24ms4012 KiB
15Accepted2/24ms4008 KiB
16Accepted2/26ms4332 KiB
17Accepted2/28ms4336 KiB
18Accepted2/28ms4348 KiB
19Accepted2/29ms4680 KiB
20Accepted2/29ms4660 KiB
21Accepted2/210ms4700 KiB
22Accepted2/210ms4696 KiB
23Accepted2/29ms4696 KiB
24Accepted2/29ms4748 KiB
25Accepted2/29ms4700 KiB
26Accepted2/29ms4744 KiB
27Accepted2/29ms4876 KiB
28Accepted2/29ms5000 KiB