61232023-11-02 21:13:50MrChipserA lehető legkevesebb átszállás (50 pont)cpp11Runtime error 32/5054ms64860 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/03ms1840 KiB
2Runtime error0/054ms64860 KiB
3Accepted1/13ms2232 KiB
4Accepted1/12ms2320 KiB
5Accepted2/23ms2444 KiB
6Accepted2/23ms2532 KiB
7Accepted2/27ms8860 KiB
8Accepted2/29ms11280 KiB
9Accepted2/210ms14596 KiB
10Accepted2/219ms21284 KiB
11Accepted2/223ms29700 KiB
12Accepted2/228ms35436 KiB
13Accepted2/28ms11236 KiB
14Accepted2/214ms18988 KiB
15Accepted2/220ms26240 KiB
16Accepted2/232ms37172 KiB
17Accepted2/245ms52124 KiB
18Accepted2/250ms57964 KiB
19Accepted2/248ms62588 KiB
20Runtime error0/248ms63160 KiB
21Runtime error0/254ms62920 KiB
22Runtime error0/246ms62900 KiB
23Runtime error0/248ms62832 KiB
24Runtime error0/250ms62604 KiB
25Runtime error0/250ms62580 KiB
26Runtime error0/245ms62560 KiB
27Runtime error0/243ms62548 KiB
28Runtime error0/243ms62316 KiB