61242023-11-02 21:14:02MrChipserA lehető legkevesebb átszállás (50 pont)cpp11Runtime error 32/5056ms64864 KiB
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main()
{
    int n,m;
    cin >> m >>n;
    vector<int> adj[n];
    vector<int> vonalszam[n];
    for(int i = 0; i < m; i++)
    {
        int a,b;
        cin >> a >> b;
        for(int j = a; j < b; j++)
        {
            adj[a-1].push_back(j);
            vonalszam[a-1].push_back(i+1);
            //cout << a << " " << j+1 << " " << i+1 << endl;
        }
    }
    queue<int>q;
    int votma[n] = {0};
    int elozo[n];
    int vonal[n];
    int tav[n] = {0};
    q.push(0);
    votma[0]=1;
    elozo[0]=-1;
    while(!q.empty())
    {
        int akt = q.front();
        q.pop();
        int k = 0;
        for(auto x : adj[akt])
        {
            if(votma[x]==0)
            {
                q.push(x);
                votma[x]=1;
                elozo[x]=akt;
                tav[x]=tav[akt]+1;
                vonal[x]= *(vonalszam[akt].begin()+k);
                //cout << akt << " " << x << " " << *(vonalszam[akt].begin()+k) << endl;
            }
            k++;
        }
    }
    cout << tav[n-1]-1<< endl;
    vector<int>ut;
    int x = n-1;
    while(x!=-1)
    {
        ut.insert(ut.begin(),x);
        x = elozo[x];
    }
    for(int i = 1; i < ut.size(); i++)
        cout << vonal[ut[i]] << " ";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base32/50
1Accepted0/03ms1812 KiB
2Runtime error0/056ms64864 KiB
3Accepted1/13ms2228 KiB
4Accepted1/13ms2472 KiB
5Accepted2/23ms2688 KiB
6Accepted2/23ms2900 KiB
7Accepted2/27ms8944 KiB
8Accepted2/28ms11684 KiB
9Accepted2/210ms14916 KiB
10Accepted2/217ms21592 KiB
11Accepted2/223ms29852 KiB
12Accepted2/227ms35576 KiB
13Accepted2/28ms11508 KiB
14Accepted2/213ms19168 KiB
15Accepted2/217ms26096 KiB
16Accepted2/232ms37412 KiB
17Accepted2/245ms52496 KiB
18Accepted2/245ms58292 KiB
19Accepted2/254ms62592 KiB
20Runtime error0/252ms62704 KiB
21Runtime error0/252ms62468 KiB
22Runtime error0/246ms62448 KiB
23Runtime error0/248ms62388 KiB
24Runtime error0/252ms62360 KiB
25Runtime error0/250ms62132 KiB
26Runtime error0/250ms62096 KiB
27Runtime error0/248ms62112 KiB
28Runtime error0/248ms62104 KiB