75022024-01-09 11:35:02gyjazminA lehető legkevesebb átszállás (50 pont)cpp17Runtime error 17/5010ms5920 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 (graf[i][0]<=cv&& i<=graf.size()-1){ 
        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 {       
        while (cv != m) {
            bool eljut = kovetk();
            if (!eljut) {
                cout << -1 << endl;
                break;
            }
        }
        cout << v.size() - 1 << endl;
        for (int i = 0;i < v.size();i++) {
            cout << v[i] << " ";
        }
        cout << endl;
    }

    
}

SubtaskSumTestVerdictTimeMemory
base17/50
1Accepted0/03ms2020 KiB
2Accepted0/010ms3208 KiB
3Runtime error0/13ms2484 KiB
4Accepted1/13ms2596 KiB
5Wrong answer0/23ms2848 KiB
6Runtime error0/23ms3152 KiB
7Accepted2/23ms3064 KiB
8Accepted2/24ms3348 KiB
9Accepted2/24ms3620 KiB
10Wrong answer0/24ms3700 KiB
11Wrong answer0/26ms3752 KiB
12Wrong answer0/27ms3952 KiB
13Wrong answer0/24ms3832 KiB
14Accepted2/24ms3828 KiB
15Accepted2/24ms4016 KiB
16Wrong answer0/27ms4376 KiB
17Wrong answer0/28ms4608 KiB
18Wrong answer0/28ms4696 KiB
19Wrong answer0/29ms4696 KiB
20Accepted2/29ms4820 KiB
21Wrong answer0/210ms5200 KiB
22Wrong answer0/210ms5292 KiB
23Runtime error0/210ms5876 KiB
24Runtime error0/29ms5860 KiB
25Accepted2/210ms5388 KiB
26Runtime error0/29ms5920 KiB
27Runtime error0/29ms5916 KiB
28Accepted2/210ms5596 KiB