86892024-01-25 12:12:13antiKerékpártúra (50 pont)cpp17Wrong answer 0/5030ms64800 KiB
#include <iostream>
#include <queue>

using namespace std;

int main()
{
    int n, m, start;
    cin >> n >> m >> start;
    start--;
    int M[n][n], IM[n][n];
    for(int i=0; i<m; i++){
        int U, V;
        cin >> U >> V;
        M[U-1][V-1] = 1;
        IM[V-1][U-1] = 1;
    }
    queue<int> q;
    int v[n]={0};

    q.push(start);
    v[start]=1;
    int x;
    while (!q.empty())
    {
        x=q.front();
        q.pop();
        for(int y=0; y<n; y++)
        {
            if (IM[x][y]==1 and v[y]==0)
            {
                q.push(y);
                v[y]=1;
            }
        }
    }
    for(int i=0; i<n; i++){
        cout << v[i] << " ";
    }
    cout << endl;
    int meg[n];
    int h=0;
    for(int i=0; i<n; i++){
        if(v[i] == 1){
            meg[h] = i;
            h++;
        }
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<n; j++){
            if(M[meg[i]][j] == 1){
                v[j] = 1;
            }
        }
    }
    v[start] = 0;
    for(int i=0; i<n; i++){
        if(v[i] == 1){
            cout << i+1 << " ";
        }
    }
    cout << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/03ms2088 KiB
2Runtime error0/028ms64800 KiB
3Wrong answer0/23ms2296 KiB
4Wrong answer0/23ms2520 KiB
5Wrong answer0/23ms2736 KiB
6Wrong answer0/23ms2948 KiB
7Wrong answer0/23ms3216 KiB
8Wrong answer0/24ms3192 KiB
9Wrong answer0/24ms3676 KiB
10Wrong answer0/24ms4556 KiB
11Wrong answer0/28ms13208 KiB
12Wrong answer0/217ms15964 KiB
13Wrong answer0/217ms18836 KiB
14Wrong answer0/228ms18844 KiB
15Runtime error0/321ms63736 KiB
16Runtime error0/426ms63712 KiB
17Runtime error0/430ms63512 KiB
18Runtime error0/330ms63276 KiB
19Runtime error0/326ms63252 KiB
20Runtime error0/325ms63224 KiB
21Runtime error0/330ms63024 KiB
22Runtime error0/326ms63012 KiB