79602024-01-12 08:56:44BotiA lehető legkevesebb átszállás (50 pont)cpp17Accepted 50/5012ms5952 KiB
#include <bits/stdc++.h>

using namespace std;

int n, m;
vector<int> a;
vector<int> b;
vector<int> ut (0);
bool eljut = true;

void bejar(int c)
{
    int max = -1;
    for (int i = 0; i < n; i++)
    {
        if (a[i] <= c && b[i] > c && (max == -1 || b[max] < b[i]))
        {
            max = i;
        }
    }
    ut.push_back(max);
    if (max == -1)
    {
        eljut = false;
    }
    else if (b[max] != m)
    {
        bejar(b[max]);
    }
}

int main()
{
    cin >> n >> m;
    a.resize (n);
    b.resize (n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }
    bejar(1);
    if (eljut)
    {
        cout << ut.size() -1 << endl;
        for (int i = 0; i < ut.size(); i++)
        {
            cout << ut[i] +1 << " ";
        }
    }
    else
    {
        cout << -1;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1876 KiB
2Accepted0/010ms2480 KiB
3Accepted1/13ms2568 KiB
4Accepted1/13ms2644 KiB
5Accepted2/23ms2732 KiB
6Accepted2/23ms2844 KiB
7Accepted2/23ms3116 KiB
8Accepted2/24ms3264 KiB
9Accepted2/24ms3528 KiB
10Accepted2/24ms3676 KiB
11Accepted2/24ms3676 KiB
12Accepted2/26ms3728 KiB
13Accepted2/23ms4024 KiB
14Accepted2/24ms4020 KiB
15Accepted2/24ms4256 KiB
16Accepted2/27ms4368 KiB
17Accepted2/28ms4588 KiB
18Accepted2/28ms4680 KiB
19Accepted2/29ms4596 KiB
20Accepted2/210ms4736 KiB
21Accepted2/212ms4912 KiB
22Accepted2/212ms5020 KiB
23Accepted2/28ms5136 KiB
24Accepted2/28ms5332 KiB
25Accepted2/28ms5504 KiB
26Accepted2/28ms5568 KiB
27Accepted2/28ms5864 KiB
28Accepted2/28ms5952 KiB