75162024-01-09 13:13:19gyjazminA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 28/509ms5256 KiB


#include <iostream>
#include <vector>
using namespace std;
vector<int> v(1);
vector<vector<int>> graf;
int cv = 0;
bool kovetk() {
    v.push_back(0);
    int eleje= cv;
    int s = v.size()-1;
    int i = v[s-1]+1;
    int maxv=cv;
    while (i <= graf.size() - 1&& graf[i][0] <= cv) {
        if (graf[i][1] > maxv) {
            maxv = graf[i][1];
            //cv = graf[i][1];
            v[s] = i;
        }        
        i++;
    }
    cv = maxv;
    if (eleje == cv) {
        return false;
    }
    else {
        return true;
    }

}
int main()
{
    int n,m;
    cin >> n>>m;
    graf.resize(n+1);    
    for (int i = 0;i < n;i++) {
        int egyik, masik;
        cin >> egyik >> masik;
        graf[i].resize(2);
        graf[i + 1].push_back(egyik);
        graf[i + 1].push_back(masik);
        if (egyik == 1) {
            cv = masik;
            v[0] = i + 1;
        }
    }
    if (cv == 0) {
        cout << -1 << endl;
    }
    else {
        bool eljut;
        while (cv != m) {
            eljut = kovetk();
            if (!eljut) {
                cout << -1 << endl;
                break;
            }
        }
        if (eljut) {
            cout << v.size() - 1 << endl;
            for (int i = 0;i < v.size();i++) {
                cout << v[i] << " ";
            }
            cout << endl;
        }
    }

    
}

SubtaskSumTestVerdictTimeMemory
base28/50
1Accepted0/03ms1936 KiB
2Accepted0/09ms3128 KiB
3Accepted1/13ms2384 KiB
4Accepted1/13ms2596 KiB
5Wrong answer0/23ms2676 KiB
6Accepted2/23ms2624 KiB
7Accepted2/23ms2740 KiB
8Accepted2/24ms2764 KiB
9Accepted2/24ms2792 KiB
10Wrong answer0/24ms2992 KiB
11Wrong answer0/26ms3044 KiB
12Wrong answer0/27ms3368 KiB
13Wrong answer0/23ms3128 KiB
14Accepted2/24ms2976 KiB
15Accepted2/24ms3172 KiB
16Wrong answer0/26ms3400 KiB
17Wrong answer0/28ms3568 KiB
18Wrong answer0/28ms3572 KiB
19Wrong answer0/28ms3704 KiB
20Accepted2/29ms3956 KiB
21Wrong answer0/29ms4296 KiB
22Wrong answer0/29ms4252 KiB
23Accepted2/29ms4504 KiB
24Accepted2/29ms4596 KiB
25Accepted2/29ms4552 KiB
26Accepted2/29ms4868 KiB
27Accepted2/29ms5040 KiB
28Accepted2/29ms5256 KiB