29042023-02-02 13:05:35gontermarkAdószedőcpp17Accepted 30/30569ms17324 KiB
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main()
{
    int n, m, fo;
    cin >> n >> m >> fo;
    int a, b;
    vector<int> csl[n+1];
    for(int i=0;i<m;i++)
    {
        cin >> a >> b;
        csl[a].push_back(b);
        csl[b].push_back(a);
    }
    queue<int> szurke;
    vector<int> t2;
    t2.resize(n+1);
    szurke.push(fo);
    t2[fo]=1;
    int p;
    vector<int> kezd;
    vector<int> veg;
    int tav[n+1];
    tav[fo]=0;
    while(!szurke.empty())
    {
        p=szurke.front();
        szurke.pop();
        t2[p]=2;
        for(int i=0; i<csl[p].size();i++)
        {
            if(t2[csl[p][i]]==0)
            {
                t2[csl[p][i]]=1;
                szurke.push(csl[p][i]);
                kezd.push_back(p);
                veg.push_back(csl[p][i]);
                tav[csl[p][i]]=tav[p]+1;
            }
            else if(csl[p][i]!=p)
            {
                if(tav[p]+1==tav[csl[p][i]])
                {
                    kezd.push_back(p);
                    veg.push_back(csl[p][i]); 
                }
            }
        }
    }
    cout << kezd.size() << endl;
    for(int i=0;i<kezd.size();i++)
    {
        cout <<kezd[i] << " " << veg[i] << endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base30/30
1Accepted0/03ms1812 KiB
2Accepted0/0296ms12032 KiB
3Accepted1/13ms2148 KiB
4Accepted1/13ms2424 KiB
5Accepted1/13ms2568 KiB
6Accepted1/13ms2784 KiB
7Accepted1/13ms2936 KiB
8Accepted1/13ms3176 KiB
9Accepted2/24ms3484 KiB
10Accepted2/24ms3464 KiB
11Accepted2/27ms3588 KiB
12Accepted2/237ms4352 KiB
13Accepted2/259ms5620 KiB
14Accepted2/2254ms11984 KiB
15Accepted1/1412ms16396 KiB
16Accepted1/1338ms13500 KiB
17Accepted2/2569ms16580 KiB
18Accepted2/2319ms16056 KiB
19Accepted2/2430ms16520 KiB
20Accepted2/2458ms17052 KiB
21Accepted2/2558ms17324 KiB