150792025-02-12 11:54:44tamasmarkA lehető legkevesebb metróval utazás (40 pont)cpp17Hibás válasz 16/40600ms1584 KiB
// leheto legkevesebb metro.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <deque>
#include <map>

using namespace std;
struct adat
{
    int lat,lep,veg,honnan;
    set<int>sz;
};
struct adat2
{
    int p;
    vector<int>sorsz;
};
map<int,vector<int> >csp;
vector<adat>x;
deque<int>q;
int akt;
int n, m, i, j, a, b,k,v;
void vissz(int csp)
{
    if (x[csp].honnan)
        vissz(x[csp].honnan);
    cout << csp << " ";
}
int main()
{
    cin >> m >> n >> k >> v;
    x.resize(m + 1);
    for (i = 1; i <= m; ++i)
    {
        cin >> a;
        for (j = 1; j <= a; ++j)
        {
            cin >> b;
            if (k == b)
            {
                q.push_back(i);
                x[i].lat = true;
                x[i].lep = 1;
            }
            if (v == b)
            {
                x[i].veg = 1;
            }
            if (csp[b].empty())
            {
                csp[b].push_back(i);
            }
            else if(!csp[b].empty())
            {
                for (auto& e : csp[b])
                {
                    x[i].sz.insert(e);
                    x[e].sz.insert(i);
                }
            }
        }
    }

    while (!q.empty())
    {
        akt = q.front();
        q.pop_front();
        x[akt].lat = true;
        for (auto& e : x[akt].sz)
        {
            if (!x[e].lat)
            {
                q.push_back(e);
                x[e].lep = x[akt].lep + 1;
                x[e].honnan = akt;
            }
        }
    }

    int mini = 9999,c;
    for (i = 1; i <= m; ++i)
    {
        if (x[i].veg && x[i].lep < mini)
        {
            mini = x[i].lep;
            c = i;
        }
    }
    cout << mini<<"\n";
    vissz(c);
    return 0;
}
/*
3 12 1 8
6 1 2 3 4 5 6
6 4 5 6 7 8 9
5 3 10 11 12 7
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base16/40
1Elfogadva0/01ms316 KiB
2Elfogadva0/08ms1332 KiB
3Elfogadva2/21ms500 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/22ms316 KiB
6Hibás válasz0/21ms316 KiB
7Elfogadva2/23ms576 KiB
8Elfogadva2/23ms568 KiB
9Elfogadva2/26ms1004 KiB
10Hibás válasz0/24ms964 KiB
11Hibás válasz0/23ms564 KiB
12Hibás válasz0/213ms1584 KiB
13Hibás válasz0/213ms1552 KiB
14Hibás válasz0/28ms1332 KiB
15Időlimit túllépés0/2600ms1212 KiB
16Időlimit túllépés0/2600ms1076 KiB
17Időlimit túllépés0/2600ms1228 KiB
18Időlimit túllépés0/2600ms1236 KiB
19Hibás válasz0/26ms1080 KiB
20Hibás válasz0/28ms1344 KiB
21Elfogadva2/24ms820 KiB
22Elfogadva2/28ms1496 KiB