96452024-02-23 17:01:14zeytonxA lehető legkevesebb metróval utazás (40 pont)cpp17Wrong answer 0/40130ms42552 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef set<ll> sll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef vector<vll> v2ll;
typedef map<ll,ll> mll;
typedef vector<pll> vpll;
typedef map<pll,ll> mpll;
typedef vector<vpll> v2pll;
typedef vector<sll> v2sll;
#define fs first
#define sc second
#define pb push_back

const ll MOD = 1e9+7;

void solve()
{
    ll n, m, ind, erk;
    cin >> n >> m >> ind >> erk;
    ind--; erk--;
    v2ll g(n);
    v2ll st(m), ls(n);
    for(ll i = 0; i < n; i++)
    {
        ll pc;
        cin >> pc;
        ls[i].resize(pc);
        for(ll &j : ls[i])
        {
            cin >> j; j--;
            st[j].pb(i);
        }
    }

    return;

    for(ll i = 0; i < m; i++)
    {
        if(!st[i].empty() && st[i].size() > 1)
            for(ll j = 0; j < st[i].size(); j++)
                for(ll l = j+1; l < st[i].size(); l++)
                {
                    g[st[i][j]].pb(st[i][l]);
                    g[st[i][l]].pb(st[i][j]);
                }
    }
    
    qll q;
    vll used(n, -1);

    for(ll i : st[ind])
    {
        q.push(i);
        used[i] = -2;
    }

    ll ans = -1;

    while(!q.empty())
    {
        ll p = q.front();
        q.pop();
        if(find(st[erk].begin(), st[erk].end(), p) != st[erk].end())
        {
            ans = p;
            break;
        }
        for(ll i : g[p])
        {
            if(used[i] == -1)
            {
                q.push(i);
                used[i] = p;
            }
        }
    }

    if(ans == -1)
    {
        cout << -1 << endl;
        return;
    }
    
    vll v_ans;
    while(ans >= 0)
    {
        v_ans.pb(ans);
        ans = used[ans];
    }
    reverse(v_ans.begin(), v_ans.end());

    cout << v_ans.size() << "\n";
    for(ll i : v_ans)
        cout << i+1 << " ";
    cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--)
        solve();
    cout << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Wrong answer0/03ms1976 KiB
2Wrong answer0/04ms3364 KiB
3Wrong answer0/23ms2244 KiB
4Wrong answer0/23ms2448 KiB
5Wrong answer0/23ms2736 KiB
6Wrong answer0/22ms2692 KiB
7Wrong answer0/23ms3108 KiB
8Wrong answer0/23ms3172 KiB
9Wrong answer0/24ms3524 KiB
10Wrong answer0/24ms3688 KiB
11Wrong answer0/23ms3508 KiB
12Wrong answer0/24ms4724 KiB
13Wrong answer0/24ms4940 KiB
14Wrong answer0/24ms5168 KiB
15Wrong answer0/2130ms42552 KiB
16Wrong answer0/2129ms42476 KiB
17Wrong answer0/2130ms42212 KiB
18Wrong answer0/2126ms42520 KiB
19Wrong answer0/24ms4780 KiB
20Wrong answer0/24ms5152 KiB
21Wrong answer0/24ms4604 KiB
22Wrong answer0/24ms5360 KiB