61202023-11-02 20:59:14MrChipserA lehető legkevesebb átszállás (50 pont)cpp11Runtime error 30/5050ms64860 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
base30/50
1Accepted0/03ms1816 KiB
2Runtime error0/050ms64860 KiB
3Accepted1/13ms2372 KiB
4Accepted1/13ms2604 KiB
5Accepted2/23ms2784 KiB
6Accepted2/23ms2924 KiB
7Accepted2/27ms9400 KiB
8Accepted2/28ms11796 KiB
9Accepted2/210ms14848 KiB
10Accepted2/216ms21568 KiB
11Accepted2/226ms29872 KiB
12Accepted2/230ms35728 KiB
13Accepted2/28ms11772 KiB
14Accepted2/214ms19672 KiB
15Accepted2/220ms26668 KiB
16Accepted2/232ms37780 KiB
17Accepted2/245ms52776 KiB
18Accepted2/250ms58572 KiB
19Runtime error0/250ms62460 KiB
20Runtime error0/250ms62448 KiB
21Runtime error0/246ms62416 KiB
22Runtime error0/246ms62176 KiB
23Runtime error0/246ms62124 KiB
24Runtime error0/250ms62084 KiB
25Runtime error0/250ms62096 KiB
26Runtime error0/243ms62096 KiB
27Runtime error0/243ms62064 KiB
28Runtime error0/243ms62036 KiB