30072023-02-08 09:48:33bzsofiaAdószedőcpp11Accepted 30/30439ms54328 KiB
// Adoszedo.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

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

using namespace std;

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

int i, n, m, a, b, kezd, akt;
map<pair<int, int>, bool> el;
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}] != 1)
                {
                    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
SubtaskSumTestVerdictTimeMemory
base30/30
1Accepted0/03ms1688 KiB
2Accepted0/0319ms44244 KiB
3Accepted1/13ms2088 KiB
4Accepted1/13ms2324 KiB
5Accepted1/13ms2400 KiB
6Accepted1/13ms2524 KiB
7Accepted1/13ms2596 KiB
8Accepted1/13ms2868 KiB
9Accepted2/24ms3372 KiB
10Accepted2/24ms3656 KiB
11Accepted2/24ms3756 KiB
12Accepted2/225ms6852 KiB
13Accepted2/257ms11940 KiB
14Accepted2/2273ms39116 KiB
15Accepted1/1363ms49704 KiB
16Accepted1/1296ms42524 KiB
17Accepted2/2439ms54148 KiB
18Accepted2/2367ms50008 KiB
19Accepted2/2379ms52632 KiB
20Accepted2/2386ms52756 KiB
21Accepted2/2402ms54328 KiB