85382024-01-21 16:43:37qertendKerékpártúra (50 pont)cpp17Időlimit túllépés 24/50474ms16664 KiB
#include <iostream>
#include <list>
using namespace std;

bool hasInt(int target, list<int> field) {
    for (int i : field) {
        if (i == target) return true;
    }
    return false;
}

int main()
{
    int numberOfNodes, routes, startID;
    cin >> numberOfNodes;
    cin >> routes;
    cin >> startID;

    struct Node {
        list<int> outgoing;
        list<int> incoming;
        void connected(list<int> &connectedByIncoming, list<int> &connectedByOutgoing,Node nodesList[]) {
            for (int i : incoming) {
                if (!hasInt(i, connectedByIncoming)) {
                    connectedByIncoming.push_back(i);
                    nodesList[i].connected(connectedByIncoming, connectedByOutgoing, nodesList);
                }
            }
            for (int i : outgoing) {
                if (!hasInt(i, connectedByOutgoing)) connectedByOutgoing.push_back(i);
            }
        }
    };
    Node nodes[numberOfNodes];

    //read all routes from stdin
    for (int i = 0; i < routes; i++) {
        int startPoint, endPoint;
        cin >> startPoint;
        cin >> endPoint;
        Node &startNode = nodes[startPoint-1];
        Node &endNode = nodes[endPoint-1];
        startNode.outgoing.push_back(endPoint-1);
        endNode.incoming.push_back(startPoint-1);
    }

    list<int> connectedByIncoming;
    list<int> connectedByOutgoing;
    nodes[startID-1].connected(connectedByIncoming, connectedByOutgoing, nodes);
    for (int i : connectedByOutgoing) {
        if (!hasInt(i, connectedByIncoming)) connectedByIncoming.push_back(i);
    }
    int size = connectedByIncoming.size();
    if (hasInt(startID-1, connectedByIncoming)) size--;
    cout << size << "\n";
    for (int i : connectedByIncoming) {
        if (i != startID - 1) cout << i+1 << " ";
    }

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base24/50
1Elfogadva0/03ms1812 KiB
2Elfogadva0/061ms6360 KiB
3Elfogadva2/23ms2120 KiB
4Elfogadva2/22ms2180 KiB
5Elfogadva2/23ms2316 KiB
6Elfogadva2/23ms2704 KiB
7Elfogadva2/23ms2644 KiB
8Elfogadva2/26ms3104 KiB
9Elfogadva2/24ms3208 KiB
10Elfogadva2/26ms3524 KiB
11Elfogadva2/28ms4012 KiB
12Elfogadva2/217ms5960 KiB
13Elfogadva2/268ms5816 KiB
14Elfogadva2/2138ms8504 KiB
15Időlimit túllépés0/3451ms6628 KiB
16Időlimit túllépés0/4453ms7164 KiB
17Időlimit túllépés0/4458ms8708 KiB
18Időlimit túllépés0/3449ms8236 KiB
19Időlimit túllépés0/3469ms7568 KiB
20Időlimit túllépés0/3474ms14936 KiB
21Időlimit túllépés0/3470ms16388 KiB
22Időlimit túllépés0/3451ms16664 KiB