75212024-01-09 13:19:48gyjazminA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 28/5010ms4836 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++;
    }
    if (i == graf.size() - 1) {
        v.erase(v.begin() + s);
    }
    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
1Wrong answer0/03ms1876 KiB
2Accepted0/09ms3152 KiB
3Accepted1/13ms2300 KiB
4Accepted1/13ms2644 KiB
5Partially correct1/23ms2596 KiB
6Wrong answer0/23ms2784 KiB
7Accepted2/23ms2920 KiB
8Accepted2/24ms3012 KiB
9Accepted2/24ms2976 KiB
10Wrong answer0/24ms3416 KiB
11Wrong answer0/26ms3552 KiB
12Partially correct1/26ms3800 KiB
13Wrong answer0/23ms3332 KiB
14Accepted2/24ms3388 KiB
15Accepted2/24ms3572 KiB
16Wrong answer0/26ms3948 KiB
17Wrong answer0/28ms3984 KiB
18Wrong answer0/28ms4120 KiB
19Wrong answer0/28ms4256 KiB
20Accepted2/29ms4232 KiB
21Wrong answer0/210ms4612 KiB
22Wrong answer0/29ms4684 KiB
23Accepted2/29ms4836 KiB
24Accepted2/29ms4684 KiB
25Accepted2/29ms4684 KiB
26Accepted2/29ms4836 KiB
27Accepted2/29ms4688 KiB
28Accepted2/29ms4688 KiB