94752024-02-22 10:17:58TortelliniJrKerékpártúra (50 pont)cpp17Time limit exceeded 47/50467ms10192 KiB
using namespace std;
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
    int p, e, s;
    int a, b;
    cin >> p >> e >> s;
    vector<vector<int>> graf(p + 1);
    vector<vector<int>> farg(p + 1);
    for (int i = 0; i < e; i++)
    {
        cin >> a >> b;
        graf[a].push_back(b);
        farg[b].push_back(a);
    }
    int curr = s;
    vector<bool> vis(p);
    vector<int> st;
    vector<int> glhf;
    int n = 0;
    while (true)
    {
        vis[curr] = true;
        for (int i = 0; i < graf[curr].size(); i++)
        {
            if (graf[curr][i] != s && glhf.end() == find(glhf.begin(), glhf.end(), graf[curr][i]))
            {
                glhf.push_back(graf[curr][i]);
            }
        }
        for (int i = 0; i < farg[curr].size(); i++)
        {
            if (find(st.begin(), st.end(), farg[curr][i]) == st.end() && !vis[farg[curr][i]])
            {
                st.push_back(farg[curr][i]);
            }
        }
        if (n < st.size())
        {
            curr = st[n];
            n++;
        }
        else
        {
            break;
        }
    }
    cout << glhf.size() << endl;
    for (int i = 0; i < glhf.size(); i++)
    {
        cout << glhf[i] << " ";
    }
}
SubtaskSumTestVerdictTimeMemory
base47/50
1Accepted0/03ms1808 KiB
2Accepted0/021ms4056 KiB
3Accepted2/23ms2112 KiB
4Accepted2/23ms2312 KiB
5Accepted2/23ms2532 KiB
6Accepted2/23ms2620 KiB
7Accepted2/23ms2860 KiB
8Accepted2/24ms2884 KiB
9Accepted2/24ms3204 KiB
10Accepted2/24ms3128 KiB
11Accepted2/27ms3320 KiB
12Accepted2/214ms3976 KiB
13Accepted2/214ms4172 KiB
14Accepted2/225ms4748 KiB
15Accepted3/343ms6296 KiB
16Accepted4/464ms6876 KiB
17Accepted4/4115ms7348 KiB
18Accepted3/3119ms7208 KiB
19Accepted3/3115ms7008 KiB
20Accepted3/3144ms9496 KiB
21Accepted3/3342ms10192 KiB
22Time limit exceeded0/3467ms6476 KiB