85412024-01-21 16:46:01qertendKerékpártúra (50 pont)cpp17Time limit exceeded 24/50477ms15552 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);
    }
    connectedByIncoming.remove(startID-1);
    int size = connectedByIncoming.size();
    cout << size << "\n";
    for (int i : connectedByIncoming) {
        cout << i+1 << " ";
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base24/50
1Accepted0/03ms1680 KiB
2Accepted0/061ms6160 KiB
3Accepted2/23ms2068 KiB
4Accepted2/23ms2272 KiB
5Accepted2/23ms2368 KiB
6Accepted2/23ms2500 KiB
7Accepted2/23ms2708 KiB
8Accepted2/26ms3176 KiB
9Accepted2/24ms3280 KiB
10Accepted2/26ms3352 KiB
11Accepted2/28ms3624 KiB
12Accepted2/216ms5364 KiB
13Accepted2/268ms5136 KiB
14Accepted2/2136ms7920 KiB
15Time limit exceeded0/3458ms6036 KiB
16Time limit exceeded0/4414ms6460 KiB
17Time limit exceeded0/4474ms7992 KiB
18Time limit exceeded0/3462ms7504 KiB
19Time limit exceeded0/3469ms7208 KiB
20Time limit exceeded0/3458ms14060 KiB
21Time limit exceeded0/3477ms15512 KiB
22Time limit exceeded0/3462ms15552 KiB