30062023-02-08 09:41:54bzsofiaAdószedőcpp11Futási hiba 16/3046ms64852 KiB
// Adoszedo.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct adat
{
    int tav;
    bool lat;
    vector <int> sz;
};

int i, n, m, a, b, kezd, akt;
queue <int> s;
vector <pair<int, int>> v;

int main()
{
    cin >> n >> m >> kezd;
    vector <adat> x(n + 1);
    vector <vector <bool>> el(n + 1, vector <bool>(n + 1));

    for (i = 1; i <= m; ++i)
    {
        cin >> a >> b;

        x[a].sz.push_back(b);
        x[b].sz.push_back(a);
    }

    x[kezd].lat = 1;
    s.push(kezd);
    while (!s.empty())
    {
        akt = s.front();
        //cout << akt << " ";
        s.pop();
        for (auto& e : x[akt].sz)
        {
            if (!x[e].lat || x[akt].tav+1==x[e].tav)
            {
                if (!x[e].lat) s.push(e);
                x[e].lat = 1;
                if (!el[e][akt])
                {
                    v.push_back({ akt,e });
                }
                el[e][akt] = el[akt][e] = 1;
                x[e].tav = x[akt].tav+1;
            }
        }
    }

    //cout << x[n].tav;

    cout << v.size() << "\n";
    for (auto& e : v)
    {
        cout << e.first << " " << e.second << "\n";
    }

    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base16/30
1Elfogadva0/03ms1812 KiB
2Futási hiba0/034ms64852 KiB
3Elfogadva1/13ms2376 KiB
4Elfogadva1/13ms2472 KiB
5Elfogadva1/13ms2684 KiB
6Elfogadva1/13ms2932 KiB
7Elfogadva1/13ms2948 KiB
8Elfogadva1/13ms3120 KiB
9Elfogadva2/24ms3772 KiB
10Elfogadva2/24ms3908 KiB
11Elfogadva2/24ms3968 KiB
12Elfogadva2/217ms8880 KiB
13Elfogadva2/246ms31448 KiB
14Futási hiba0/227ms63244 KiB
15Futási hiba0/127ms63000 KiB
16Futási hiba0/127ms62996 KiB
17Futási hiba0/227ms62760 KiB
18Futási hiba0/232ms62728 KiB
19Futási hiba0/227ms62488 KiB
20Futási hiba0/227ms62484 KiB
21Futási hiba0/230ms62244 KiB